dita-key-scopes
Reuse the same DITA key name in more than one place without collisions, using DITA 1.3 key scopes (@keyscope). Use when a key resolves to the wrong target because two parts of a map (or two reused submaps) define the same key, when combining guides into one collection, or when asked to scope keys per section/edition/branch.
- License 许可
- Apache-2.0
- 最近更新
- 2026-10-20
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- dita-key-scopes
- description
- Reuse the same DITA key name in more than one place without collisions, using DITA 1.3 key scopes (@keyscope). Use when a key resolves to the wrong target because two parts of a map (or two reused submaps) define the same key, when combining guides into one collection, or when asked to scope keys per section/edition/branch.
03 SKILL.md 正文
DITA 1.3 key scopes (@keyscope)
A key scope lets the same bare key name bind to different definitions in
different parts of a map. @keyscope="s" on a map/topicref/topicgroup names a scope:
keys defined inside it bind locally as key and externally as s.key. Inner scopes
shadow outer ones. This is the mechanism for reusing a sub-publication many times
(e.g. several guides in one collection, or a section duplicated per edition) without
their keys clashing. Tools: list_keys, resolve_key (with a --scope), edit_map.
When you need a scope (the symptom)
Without scopes, a map flattens all keys into one namespace and first-definition
wins. So if two reused submaps each define start-here (or product-name,
intro…), only one survives and the others are silently shadowed — a key resolves to
the wrong topic. That silent collision is the signal to introduce a scope. (Contrast
[[dita-keys]] merge_keydefs, which removes a shadowed duplicate you don't want —
here you keep both, kept apart by scope.)
Process
- Confirm the collision.
list_keys <map>— if a key you expect in several places appears once (or resolves to the wrong file), the definitions are colliding in one flat namespace. Across the whole project,project_graphshows it directly: ashadowed-keyissue names the losing definition, severalkeytargetedges for one key carry differentviamaps, andkey-resolves-inconsistentlynames the deliverables where a key fails ([[dita-project-graph]]). - Scope each reuse. Put the colliding subtrees under their own
@keyscope. For a collection that maprefs several guides, scope each mapref:edit_map <map> set-attr --ref <selector> --name keyscope --value <scope>(the selector is an@idor a 1-based child path like/2/1). Dry-run first. - Verify per scope. Keys now coexist as
scope.key:list_keys <map>shows the fully-qualified names (userguide.start-here,podcaster.start-here).resolve_key <key> --scope <scope>resolves a bare key as referenced from that scope (it walks outward to the root if the scope doesn't define it). Same key name, a different binding per scope.
What scoping fixes (it propagates)
Scoping isn't just resolve_key. Every key consumer becomes scope-aware:
list_keys (qualified names), where_used (finds a scoped key's references),
conref_audit and the publication-set crawl (resolve scoped targets), and the DITA
preview (renders the scoped binding). So fixing the scope fixes the key everywhere
it's used, not just where it's defined.
Honest limits (say these)
- In-process resolution is exact when you name the scope (
--scope) or when a bare key is unique to a single scope. - Scope a topic inherits from where a map places it (cross-file) is the engine's
job at build time; in-process a bare
keyrefin topic content is read in the root scope (a unique-scope fallback bridges the common case but can't disambiguate a name defined in several scopes). - Branch filtering ([[dita-branch-filtering]]) auto-generates a key scope per branch
(via
dvrKeyscope*), so each filtered variant gets a distinct key binding.
Report
The collision found (which key, which definitions), the scopes introduced and on which
maprefs/subtrees, and the per-scope resolution (scope.key → target) proving the keys
now coexist. For the rest of the key lifecycle (keyify/rename/merge/inline) use
[[dita-keys]].
04 同仓库更多 Skills
valid-skill
A valid test skill for unit testing.
wrong-name
Name does not match directory.
missing-description
暂无简介
hidden-skill
A skill hidden from model invocation.
dita-subject-schemes
Author or repair a DITA subjectScheme that governs conditional-processing attribute values (@platform, @audience, @product, @props, @otherprops), then validate content against it. Use when introducing controlled values, governing conditional content, or when validate_conditions reports controlled-value violations.
dita-shortdesc
Write SEO-friendly DITA shortdescs and abstracts — a standalone one-sentence summary that doubles as the link preview and the HTML meta description. Use when asked to add or improve a topic's description/abstract, write shortdescs, fill missing ones, or make descriptions SEO-friendly.