core
Expand
Substitute a registered entity's source content inline — symmetric with xref but inlines the content instead of linking to it
Source
import Markdoc from '@markdoc/markdoc';
import type { Config, Node, Schema } from '@markdoc/markdoc';
import { declareUniversalPosture } from '../lib/index.js';
const { Tag } = Markdoc;
export const EXPAND_PLACEHOLDER_MARKER = 'expand-pending';
export const expand: Schema = {
selfClosing: true,
attributes: {
primary: {
type: String,
required: true,
description: 'Entity ID or name to substitute inline. Same lookup chain as xref.',
},
level: {
type: Number,
required: false,
description:
'Optional heading-demotion opt-in. When set, embedded headings shift by `N - 1` and the embed joins the host outline instead of staying TOC-isolated.',
},
type: {
type: String,
required: false,
description:
'Entity type hint for disambiguation when the same ID/name lives in multiple registries.',
},
canonical: {
type: Boolean,
required: false,
description:
'When true, append a visible "View canonical" link pointing at the entity\'s canonical URL.',
},
label: {
type: String,
required: false,
description: 'Custom label for the canonical link (only meaningful when `canonical=true`).',
},
},
transform(node: Node, _config: Config) {
const id = node.attributes.primary as string;
const level = node.attributes.level as number | undefined;
const typeHint = node.attributes.type as string | undefined;
const canonical = node.attributes.canonical === true;
const label = node.attributes.label as string | undefined;
const attrs: Record<string, unknown> = {
'data-rune': EXPAND_PLACEHOLDER_MARKER,
'data-expand-id': id,
};
if (typeof level === 'number') attrs['data-expand-level'] = String(level);
if (typeHint) attrs['data-expand-type'] = typeHint;
if (canonical) attrs['data-expand-canonical'] = 'true';
if (label) attrs['data-expand-label'] = label;
// A `div`, not a `span`: the substituted content is block-level.
return new Tag('div', attrs, []);
},
};
declareUniversalPosture(expand, 'none');
{% expand %} finds an entity the way {% ref %} does, and places the entity's content on the page instead of a link to it: embed a decision record in a blog post about it, or show the spec beside the docs that implement it. The content stays in one file, so every embed updates when it changes. To link to the entity instead, use xref; to link to a project file rather than an entity, use file-ref; to keep the content one click away, put it in a drawer.
Basic usage
Give the entity's ID. The work item below is rendered from its plan file:
{% expand "WORK-026" /%}<div data-rune="expand-pending" data-expand-id="WORK-026"></div><section data-entity-id="WORK-026" data-entity-type="work" data-source="registry" data-outline-scope="WORK-026" class="rf-expand" data-rune="expand" data-density="full">
<article class="rf-work rf-work--WORK-026 rf-work--done rf-work--medium rf-work--trivial" data-id="WORK-026" data-status="done" data-priority="medium" data-complexity="trivial" data-assignee="" data-milestone="" data-source="SPEC-008,SPEC-021" data-supersedes="" data-pr="" data-tags="runes, core" data-created="" data-modified="" data-rune="work" data-density="full">
<div data-name="eyebrow" data-zone="eyebrow" data-zone-layout="bar" class="rf-work__eyebrow">
<span data-meta-type="id" data-field="id">WORK-026</span>
<span data-meta-type="status" data-meta-sentiment="positive" data-align="end" data-field="status">done</span>
</div>
<header data-name="title" class="rf-work__title" data-section="title">
<h1 id="WORK-026--add-ref-as-alias-for-xref">
Add
<code>ref</code>
as Alias for
<code>xref</code>
</h1>
</header>
<dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-work__metadata">
<div data-name="row" data-field="priority" class="rf-work__row">
<dt data-meta-label="">Priority</dt>
<dd>
<span data-meta-type="category" data-meta-sentiment="neutral">medium</span>
</dd>
</div>
<div data-name="row" data-field="complexity" class="rf-work__row">
<dt data-meta-label="">Complexity</dt>
<dd>
<span data-meta-type="quantity">trivial</span>
</dd>
</div>
<div data-name="row" data-field="source" class="rf-work__row">
<dt data-meta-label="">Source</dt>
<dd>
<span data-meta-type="id">SPEC-008,SPEC-021</span>
</dd>
</div>
</dl>
<div data-name="tags" data-zone="tags" data-zone-layout="bar" class="rf-work__tags">
<span data-meta-type="tag" data-field="tags">runes</span>
<span data-meta-type="tag" data-field="tags">core</span>
</div>
<div data-name="intro" class="rf-work__intro" data-section="body">
<blockquote data-quote="quotation">
<p>
Ref:
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-021">SPEC-021</span>
(Plan Runes)
</p>
</blockquote>
</div>
<div data-name="body" class="rf-work__body" data-section="body">
<section data-name="summary" class="rf-work__summary">
<h2 id="WORK-026--summary">Summary</h2>
<p>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-021">SPEC-021</span>
uses
<code>{% ref "SPEC-008" /%}</code>
syntax for cross-references. The codebase has
<code>{% xref %}</code>
. Add
<code>ref</code>
as an alias for
<code>xref</code>
so both syntaxes work. This keeps the plan spec examples valid and provides a shorter, more natural syntax for inline references.
</p>
</section>
<section data-name="acceptance-criteria" class="rf-work__acceptance-criteria">
<h2 id="WORK-026--acceptance-criteria" data-known-section="Acceptance Criteria">Acceptance Criteria</h2>
<ul>
<li data-checked="checked">
<code>{% ref "SPEC-008" /%}</code>
produces identical output to
<code>{% xref "SPEC-008" /%}</code>
</li>
<li data-checked="checked">
<code>ref</code>
registered as alias in the xref tag schema (
<code>packages/runes/src/tags/xref.ts</code>
)
</li>
<li data-checked="checked">
All xref attributes work with the
<code>ref</code>
alias (label, type)
</li>
<li data-checked="checked">Test verifying alias produces same output</li>
</ul>
</section>
<section data-name="approach" class="rf-work__approach">
<h2 id="WORK-026--approach" data-known-section="Approach">Approach</h2>
<p>
Add
<code>ref</code>
to the xref tag's
<code>aliases</code>
array in the Markdoc schema definition. No changes to the transform logic needed — Markdoc handles alias resolution automatically.
</p>
</section>
</div>
</article>
</section>What can be embedded
Any entity whose source the build can read back: a spec, a work item, a decision, a character. Pages and headings cannot be embedded; the build reports an error naming the entity. Runes inside the embedded content render as they would on their own page, and references inside it resolve as they do on the host page.
An entity cannot embed itself, directly or through another embed; the build fails and names the loop. Embedding the same entity on several pages is fine.
Show it in a drawer
Put the embed in a drawer and open it with a {% ref %}: the reader gets the full entity in a side panel and stays on the page.
The expand rune has a written specification. {% ref "spec-066-preview" label="Open it" /%} (or press `s`) to read it without leaving the page.
{% drawer id="spec-066-preview" title="SPEC-066 — Expand rune" shortcut="s" size="lg" %}
{% expand "SPEC-066" canonical=true label="View full spec source" /%}
{% /drawer %}<p>
The expand rune has a written specification.
<span data-rune="xref" data-xref-id="spec-066-preview" data-xref-label="Open it">Open it</span>
(or press
<code>s</code>
) to read it without leaving the page.
</p>
<section id="drawer-spec-066-preview" data-rune="drawer" data-rune-fields="{"side":"right","size":"lg","shortcut":"s"}" data-drawer-id="spec-066-preview">
<header data-name="header">
<h3 data-drawer-title-auto="true" data-name="title">SPEC-066 — Expand rune</h3>
<button type="button" aria-label="Close" hidden data-name="close">×</button>
</header>
<div data-name="body">
<div data-rune="expand-pending" data-expand-id="SPEC-066" data-expand-canonical="true" data-expand-label="View full spec source"></div>
</div>
</section>The expand rune has a written specification. Open it (or press s) to read it without leaving the page.
SPEC-066 — Expand rune
<p>
The expand rune has a written specification.
<a class="rf-xref rf-xref--drawer" href="#drawer-spec-066-preview" data-xref-id="spec-066-preview" data-xref-source="registry" data-target-type="drawer">Open it</a>
(or press
<code>s</code>
) to read it without leaving the page.
</p>
<section id="drawer-spec-066-preview" class="rf-drawer rf-drawer--right rf-drawer--lg" data-drawer-id="spec-066-preview" data-side="right" data-size="lg" data-shortcut="s" data-rune="drawer" data-density="compact">
<header data-name="header" class="rf-drawer__header" data-section="header">
<h3 data-name="title" class="rf-drawer__title">SPEC-066 — Expand rune</h3>
<button type="button" aria-label="Close" hidden data-name="close" class="rf-drawer__close">×</button>
</header>
<div data-name="body" class="rf-drawer__body" data-section="body">
<section data-entity-id="SPEC-066" data-entity-type="spec" data-source="registry" data-outline-scope="SPEC-066" class="rf-expand" data-rune="expand" data-density="full">
<article class="rf-spec rf-spec--SPEC-066 rf-spec--shipped" data-id="SPEC-066" data-status="shipped" data-version="" data-supersedes="" data-released-in="v0.15.0" data-tags="runes, transclusion, registry, core" data-created="" data-modified="" data-rune="spec" data-density="full">
<div data-name="eyebrow" data-zone="eyebrow" data-zone-layout="bar" class="rf-spec__eyebrow">
<span data-meta-type="id" data-field="id">SPEC-066</span>
<span data-meta-type="status" data-meta-sentiment="positive" data-align="end" data-field="status">shipped</span>
</div>
<header data-name="title" class="rf-spec__title" data-section="title">
<h1 id="SPEC-066--expand-rune">Expand rune</h1>
</header>
<div data-name="blurb" class="rf-spec__blurb" data-section="description">
<p>A core rune that takes a registered entity ID and substitutes the entity's source content inline. Generic over entity types — works for plan specs, characters, organizations, events, or anything else a plugin registers with embeddable content. Symmetric with xref: same registry, same lookup chain, different output mode (inline content rather than a link).</p>
<p>
The motivating use case is in-context plan-content previews via
<code>{% drawer %}{% expand "SPEC-023" /%}{% /drawer %}</code>
, but the same machinery serves any plugin that registers entities with extractor information. The accompanying plan-plugin work to scan and register plan entities unconditionally is captured in
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-064">SPEC-064</span>
.
</p>
<p>
Lives in
<code>@refrakt-md/runes</code>
alongside xref. The name
<code>expand</code>
avoids collision with the existing
<code>{% embed %}</code>
rune for media URLs.
</p>
</div>
<dl data-name="metadata" data-zone="metadata" data-zone-layout="definition-list" class="rf-spec__metadata">
<div data-name="row" data-field="released-in" class="rf-spec__row">
<dt data-meta-label="">Released in</dt>
<dd>
<span data-meta-type="tag">v0.15.0</span>
</dd>
</div>
</dl>
<div data-name="tags" data-zone="tags" data-zone-layout="bar" class="rf-spec__tags">
<span data-meta-type="tag" data-field="tags">runes</span>
<span data-meta-type="tag" data-field="tags">transclusion</span>
<span data-meta-type="tag" data-field="tags">registry</span>
<span data-meta-type="tag" data-field="tags">core</span>
</div>
<div data-name="body" class="rf-spec__body" data-section="body">
<h2 id="SPEC-066--problem">Problem</h2>
<p>
Authors writing about a domain entity often want to
<em marker="*">show</em>
it in context, not just link to it. A blog post about an architecture decision reads better with the ADR inline; a worldbuilding companion site benefits from rendering a character's full description next to the prose mentioning them; a docs page can illustrate a spec it implements by embedding the spec directly.
</p>
<p>The existing primitives don't cover this:</p>
<ul>
<li>
<strong marker="**">
xref /
<code>{% ref %}</code>
</strong>
produces a link. Reader navigates away to see content.
</li>
<li>
<strong marker="**">
partial /
<code>{% partial %}</code>
</strong>
transcludes a file by path. Authoring requires knowing the exact file path; doesn't compose with the registry; doesn't carry the entity's identity into the output.
</li>
<li>
<strong marker="**">Hand-copying</strong>
the content drifts the moment the canonical version is edited.
</li>
</ul>
<p>
Every refrakt plugin that registers entities into the
<code>EntityRegistry</code>
already has the data structure that would support inline embedding — title, status, source location, type. What's missing is a generic transclusion mechanism that consults the registry, fetches the source, and substitutes it inline with cross-cutting affordances (TOC isolation, heading-ID namespacing, cycle detection, canonical-link).
</p>
<p>
The architecture mirrors xref exactly:
<code>xref</code>
resolves an ID to a
<strong marker="**">URL</strong>
;
<code>expand</code>
resolves the same ID to
<strong marker="**">content</strong>
. They share the registry as the lookup substrate but diverge on what they need from the entity record.
</p>
<hr />
<h2 id="SPEC-066--design-principles">Design Principles</h2>
<p>
<strong marker="**">Symmetric with xref.</strong>
Same registry lookup chain (exact ID → name match → fail). Same entity-type-hint disambiguation. Different output: xref renders an anchor, expand substitutes the entity's source AST. Authors who know xref already know how expand resolves.
</p>
<p>
<strong marker="**">Plugin-owned extraction.</strong>
Plugins know their own entity shapes — a plan rune is one file with one top-level entity; a character rune might be one of several siblings in a definition file. The plugin provides the extractor (
<code>extract(parsedAst) → embeddable subtree</code>
); expand calls it. The rune itself stays type-agnostic.
</p>
<p>
<strong marker="**">Implicit embeddability.</strong>
If a registration includes
<code>sourceFile</code>
+
<code>extract</code>
, the entity is embeddable. If not, expand fails with a clear "type does not support embedding" error. No separate
<code>embeddable: true</code>
flag; the presence of extraction information
<em marker="*">is</em>
the signal.
</p>
<p>
<strong marker="**">Local files only.</strong>
expand reads from the file system, sandboxed to the project root (same security boundary as snippet from
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-062">SPEC-062</span>
). No remote source fetching at build time. Users embedding plan content hosted externally on a third-party service (trace, etc.) need the source files locally; xref handles the external-URL case for refs without requiring local source.
</p>
<p>
<strong marker="**">Canonical-link via the xref resolver.</strong>
The
<code>.rf-expand</code>
wrapper includes a canonical-link affordance pointing at the entity's authoritative URL. That URL is resolved via the same chain as xref: registry
<code>sourceUrl</code>
→ SPEC-065 patterns → unresolved. So an entity embedded inline with
<code>expand</code>
and linked elsewhere with
<code>ref</code>
produces a consistent canonical URL.
</p>
<p>
<strong marker="**">One source of truth for presentation.</strong>
expand wraps the substituted content but does not construct its own header. The embedded rune (plan rune, character rune, etc.) renders itself exactly as it would standalone, plus expand's thin wrapper. Status badges, titles, structure — all come from the embedded rune's own output. No second presentation layer to drift.
</p>
<p>
<strong marker="**">Neutral conventions for cross-cutting behavior.</strong>
TOC isolation and heading-ID namespacing are driven by a neutral
<code>data-outline-scope</code>
attribute that any rune can set — not by expand-specific markers. The TOC walker and heading-ID walker consume the attribute generically; expand is one of several potential producers (future asides, sidenotes, quotes, panels, drawers may all opt into the same convention). Keeps coupling out of cross-cutting machinery.
</p>
<hr />
<h2 id="SPEC-066--authoring-surface">Authoring Surface</h2>
<h3 id="SPEC-066--syntax">Syntax</h3>
<div class="rf-codeblock">
<pre data-language="markdoc"><code data-language="markdoc">{# Basic embed — substitutes the entity inline #}
{% expand "SPEC-023" /%}
{# Optional explicit demotion — embed is meant to act as a sub-section
of the host page rather than a peer document. Rare; advanced use. #}
{% expand "SPEC-023" level=3 /%}
{# Type-hint disambiguation when the same string matches multiple types #}
{% expand "Veshra" type="character" /%}
{# Show a visible "View canonical" link — useful when the embed is a peek
and the canonical lives elsewhere (e.g. on trace) #}
{% expand "SPEC-023" canonical=true /%}
{# Headline composition — in-context preview in a drawer, with
canonical link to bridge back to the full view #}
{% drawer title="SPEC-023" shortcut="s" %}
View spec
---
{% expand "SPEC-023" canonical=true /%}
{% /drawer %}
</code></pre>
</div>
<h3 id="SPEC-066--attributes">Attributes</h3>
<div class="rf-table-wrapper">
<table>
<thead>
<tr>
<th>Attribute</th>
<th>Type</th>
<th>Required</th>
<th>Default</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>primary</code>
</td>
<td>string</td>
<td>yes</td>
<td>—</td>
<td>Entity ID or name to expand. Same shape as xref's primary.</td>
</tr>
<tr>
<td>
<code>level</code>
</td>
<td>number</td>
<td>no</td>
<td>unset</td>
<td>
Opt-in heading demotion. When unset (default), embedded headings keep their natural levels — the embed renders as its own document. When set to N, demote all headings by
<code>N - 1</code>
so the top heading becomes
<code>Hn</code>
. Rarely needed; useful only when the embed is genuinely meant to act as a sub-section of the host.
</td>
</tr>
<tr>
<td>
<code>type</code>
</td>
<td>string</td>
<td>no</td>
<td>—</td>
<td>Entity type hint for disambiguation. Constrains both registry lookup and (informally) extractor selection.</td>
</tr>
<tr>
<td>
<code>canonical</code>
</td>
<td>boolean</td>
<td>no</td>
<td>
<code>false</code>
</td>
<td>
When
<code>true</code>
, render a visible
<code>.rf-expand__canonical-link</code>
linking to the entity's canonical URL (resolved via the xref chain). When
<code>false</code>
, no visible affordance — but
<code>data-canonical-href</code>
on the wrapper is still populated for themes and tooling.
</td>
</tr>
</tbody>
</table>
</div>
<hr />
<h2 id="SPEC-066--output-contract">Output Contract</h2>
<div class="rf-codeblock">
<pre data-language="html"><code data-language="html"><!-- Default — canonical=false, no visible link, data attribute populated -->
<section class="rf-expand"
data-rune="expand"
data-entity-id="SPEC-023"
data-entity-type="spec"
data-outline-scope="SPEC-023"
data-canonical-href="https://trace.refrakt.md/user/repo/specs/SPEC-023">
<!-- The full rendered output of the embedded plan rune,
with heading levels demoted by (level - 1). -->
<section class="rf-spec" data-status="accepted">
<header class="rf-spec__header">…</header>
<div class="rf-spec__body">…</div>
</section>
</section>
<!-- With canonical=true — visible link appended after the embedded content -->
<section class="rf-expand"
data-rune="expand"
data-entity-id="SPEC-023"
data-entity-type="spec"
data-outline-scope="SPEC-023"
data-canonical-href="https://trace.refrakt.md/user/repo/specs/SPEC-023">
<section class="rf-spec" data-status="accepted">
<header class="rf-spec__header">…</header>
<div class="rf-spec__body">…</div>
</section>
<a class="rf-expand__canonical-link"
href="https://trace.refrakt.md/user/repo/specs/SPEC-023">
View canonical
</a>
</section>
</code></pre>
</div>
<p>BEM:</p>
<ul>
<li>
<code>.rf-expand</code>
— wrapper around the embedded entity
</li>
<li>
<code>.rf-expand__canonical-link</code>
— optional affordance linking to the entity's canonical URL (rendered only when
<code>canonical=true</code>
)
</li>
</ul>
<p>Data attributes (all on the wrapper):</p>
<ul>
<li>
<code>data-rune="expand"</code>
</li>
<li>
<code>data-entity-id</code>
— the resolved entity's ID
</li>
<li>
<code>data-entity-type</code>
— the entity type (
<code>spec</code>
,
<code>character</code>
, etc.)
</li>
<li>
<code>data-outline-scope</code>
— value set to the entity ID; marker for the neutral TOC-isolation + heading-ID-namespacing convention (see Heading Handling)
</li>
<li>
<code>data-canonical-href</code>
— mirrors the canonical link's
<code>href</code>
for tooling
</li>
<li>
<code>data-source</code>
—
<code>"registry"</code>
(entity was found in registry) — same convention as xref
</li>
</ul>
<p>
The inner content (
<code>.rf-spec</code>
,
<code>.rf-character</code>
, etc.) is whatever the embedded entity's rune produces. Themes can target embedded-specific styling via
<code>.rf-expand .rf-spec</code>
(etc.) without affecting standalone rendering.
</p>
<hr />
<h2 id="SPEC-066--resolution">Resolution</h2>
<p>
For each
<code>{% expand %}</code>
placeholder found during postProcess:
</p>
<ol>
<li>
<strong marker="**">Registry exact-ID match</strong>
:
<code>registry.getById(typeHint?, primary)</code>
. Optionally filtered by
<code>type</code>
hint.
</li>
<li>
<strong marker="**">Registry name fallback</strong>
: case-insensitive match against entity
<code>name</code>
/
<code>title</code>
. Same algorithm as xref.
</li>
<li>
<strong marker="**">Embeddability check</strong>
: the resolved entity must have both
<code>sourceFile</code>
and
<code>extract</code>
in its registration. If not, fail the build:
<div class="rf-codeblock">
<pre data-language="shell"><code data-language="shell">Error: expand "SPEC-023" — entity type "spec" does not support embedding.
The entity exists in the registry but has no embeddable source. Likely
causes: the plugin that owns this entity type doesn't provide expand
support, or the registration omitted sourceFile/extract.
Referenced from: site/content/blog/auth.md:24
</code></pre>
</div>
</li>
<li>
<strong marker="**">Source read</strong>
(cached per build): read
<code>sourceFile</code>
from the project root. Sandbox rules from
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-062">SPEC-062</span>
apply — no traversal, no symlink escape.
</li>
<li>
<strong marker="**">Parse</strong>
(cached per build):
<code>Markdoc.parse(source)</code>
.
</li>
<li>
<strong marker="**">Extract</strong>
: call the entity's registered
<code>extract(parsedAst) → Markdoc.Node | null</code>
. If it returns null, fail the build:
<div class="rf-codeblock">
<pre data-language="shell"><code data-language="shell">Error: expand "SPEC-023" — extractor returned no content.
The source file (plan/specs/SPEC-023-foo.md) was read but the plugin's
extractor couldn't locate the entity's content in the parsed AST. The
file may have been edited out-of-sync with the registry.
</code></pre>
</div>
</li>
<li>
<strong marker="**">Heading processing</strong>
: applied by the generic heading-ID walker (not expand-specific) once the wrapper has
<code>data-outline-scope</code>
set. Each
<code>heading</code>
node's
<code>id</code>
is prefixed with
<code>{scope-value}--</code>
(e.g.,
<code>SPEC-023--</code>
). If
<code>level=N</code>
was set on the expand rune, expand additionally shifts the heading level by
<code>N - 1</code>
(clamping at H6 with a build warning, see Heading Handling below).
</li>
<li>
<strong marker="**">Cycle check</strong>
: if the resolved
<code>(type, id)</code>
is already in the current resolution stack, fail with the cycle path.
</li>
<li>
<strong marker="**">Substitute</strong>
: replace the
<code>expand</code>
placeholder with the (heading-processed) extracted subtree, wrapped in
<code>.rf-expand</code>
markup.
<code>data-outline-scope</code>
on the wrapper (set to the entity ID) is the neutral marker the TOC walker and the heading-ID walker both honor.
</li>
<li>
<strong marker="**">Canonical-link resolution</strong>
: resolve the entity's canonical URL via the standard xref resolver chain (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-065">SPEC-065</span>
: registry
<code>sourceUrl</code>
→ patterns → unresolved). Set
<code>data-canonical-href</code>
on the wrapper regardless of the
<code>canonical</code>
attribute value — themes and tooling can always reach the URL. When
<code>canonical=true</code>
, additionally render a
<code>.rf-expand__canonical-link</code>
<code><a></code>
element with the resolved
<code>href</code>
. When
<code>canonical=true</code>
<em marker="*">and</em>
the URL resolves unresolved (no registry hit, no pattern match), render the link with
<code>rf-xref--unresolved</code>
styling (or omit the visible link — see Open Questions).
</li>
</ol>
<p>The substituted subtree is then re-processed by the host page's normal transform pipeline — embedded plan runes execute their own transforms, embedded refs resolve via the same xref chain, etc. expand doesn't pre-resolve any of that; it just provides the embedded AST as a peer of inline content.</p>
<hr />
<h2 id="SPEC-066--heading-handling">Heading Handling</h2>
<p>
Embedded entities are
<em marker="*">quoted documents</em>
, not subsections of the host. An embedded spec keeps its own H1, its own structural hierarchy, its own anchor links. The host page's heading outline and TOC stay clean of the embed's structure. Three mechanisms cooperate to deliver this:
</p>
<h3 id="SPEC-066--1-no-demotion-by-default">1. No demotion by default</h3>
<p>
Embedded headings retain their natural levels. A spec's H1 stays H1, its H2s stay H2s. This is structurally correct — HTML5 sectioning content (
<code><section></code>
,
<code><article></code>
,
<code><dialog></code>
) scopes headings to their containing element, so an H1 inside
<code>.rf-expand</code>
(or inside a drawer's
<code><dialog></code>
) represents the heading of
<em marker="*">that section</em>
, not the document root. Screen readers and the modern outline algorithm handle this correctly.
</p>
<h3 id="SPEC-066--2-toc-builder-respects-data-outline-scope">
2. TOC builder respects
<code>data-outline-scope</code>
</h3>
<p>
The host page's TOC walker (used by
<code>{% toc %}</code>
and similar tooling) skips any
<code>heading</code>
node descended from an element with a
<code>data-outline-scope</code>
attribute. The host's TOC reflects only the host's structure; the embed's headings never appear in it.
</p>
<p>
<code>data-outline-scope</code>
is a
<em marker="*">neutral convention</em>
, not an expand-specific marker. The attribute means "this subtree is a sub-outline boundary"; the TOC walker doesn't need to know about expand or any other rune. Other runes can adopt the same attribute and get the same behavior — a future
<code>{% sidenote %}</code>
,
<code>{% aside %}</code>
, or
<code>{% quote %}</code>
rune that contains its own headings can set
<code>data-outline-scope</code>
and be TOC-isolated automatically. Drawers (rendered as
<code><dialog></code>
) can set it too for explicit isolation, even though
<code><dialog></code>
is already a sectioning root semantically.
</p>
<p>
expand sets
<code>data-outline-scope</code>
on its wrapper, with the value set to the resolved entity's ID (e.g.,
<code>data-outline-scope="SPEC-023"</code>
).
</p>
<h3 id="SPEC-066--3-heading-ids-are-namespaced-via-the-scope-value">3. Heading IDs are namespaced via the scope value</h3>
<p>
Heading anchor IDs inside an element with
<code>data-outline-scope</code>
are prefixed with the scope value plus
<code>--</code>
:
</p>
<div class="rf-codeblock">
<pre data-language="html"><code data-language="html"><section class="rf-expand" data-outline-scope="SPEC-023" data-entity-id="SPEC-023">
<section class="rf-spec">
<h1 id="SPEC-023--auth-system">Auth system</h1>
<h2 id="SPEC-023--acceptance-criteria">Acceptance criteria</h2>
…
</section>
</section>
</code></pre>
</div>
<p>
The same generic mechanism: a heading-ID walker sees
<code>data-outline-scope</code>
on an ancestor element and prefixes the ID accordingly. expand doesn't own the namespacing logic — it just sets the scope attribute.
</p>
<p>Two consequences:</p>
<ul>
<li>
A host page with its own "Acceptance criteria" heading and an embedded spec with the same heading text don't collide on ID — host gets
<code>#acceptance-criteria</code>
, embed gets
<code>#SPEC-023--acceptance-criteria</code>
.
</li>
<li>
Deep links into embedded content are possible:
<code>/host-page#SPEC-023--acceptance-criteria</code>
points at the specific heading within the embed.
</li>
</ul>
<p>
ID normalization (kebab-case, ASCII slug, etc.) follows the standard heading-ID conventions for the suffix portion; the prefix is the literal value of the nearest enclosing
<code>data-outline-scope</code>
attribute.
</p>
<h3 id="SPEC-066--optional-explicit-demotion-level-merges-embed-into-host-outline">
Optional explicit demotion (
<code>level=</code>
) — merges embed into host outline
</h3>
<p>
For the rare case where an embed is genuinely meant to act as a sub-section of the host — say, a layout file that embeds a shared "section template" entity that should be styled as a sub-section — the author can opt in with
<code>level=N</code>
. This signals a different intent: the embed is no longer a quoted document; it's authored sub-content.
</p>
<p>
When
<code>level=N</code>
is set,
<strong marker="**">
expand does not emit
<code>data-outline-scope</code>
</strong>
. Three consequences follow:
</p>
<ol>
<li>
<strong marker="**">TOC walker includes the embedded headings.</strong>
They appear in the host's TOC as sub-section entries, which is what the author wants when treating the embed as part of their structure.
</li>
<li>
<strong marker="**">Heading IDs go through the normal slugifier</strong>
(no scope-value prefix). Authors accept the same ID-collision risk they'd have if they'd authored the content inline. A future heading-uniqueness linter would surface real collisions; that's a generic concern, not expand-specific.
</li>
<li>
<strong marker="**">
Heading levels are shifted by
<code>N - 1</code>
</strong>
so the embed's top heading becomes
<code>Hn</code>
.
</li>
</ol>
<p>
The two modes — peer-document (default) and sub-section (
<code>level=</code>
set) — are deliberately a binary choice. The orthogonal case (demote visually but stay TOC-isolated) is better handled in CSS by targeting
<code>.rf-expand h1</code>
,
<code>.rf-expand h2</code>
, etc., than by expanding the attribute surface.
</p>
<p>Demotion table:</p>
<div class="rf-table-wrapper">
<table>
<thead>
<tr>
<th>
<code>level=</code>
</th>
<th>data-outline-scope</th>
<th>TOC includes?</th>
<th>H1 →</th>
<th>H2 →</th>
<th>H3 →</th>
</tr>
</thead>
<tbody>
<tr>
<td>unset (default)</td>
<td>set to entity ID</td>
<td>no (isolated)</td>
<td>H1</td>
<td>H2</td>
<td>H3</td>
</tr>
<tr>
<td>
<code>1</code>
</td>
<td>not emitted</td>
<td>yes (sub-section)</td>
<td>H1</td>
<td>H2</td>
<td>H3</td>
</tr>
<tr>
<td>
<code>2</code>
</td>
<td>not emitted</td>
<td>yes (sub-section)</td>
<td>H2</td>
<td>H3</td>
<td>H4</td>
</tr>
<tr>
<td>
<code>3</code>
</td>
<td>not emitted</td>
<td>yes (sub-section)</td>
<td>H3</td>
<td>H4</td>
<td>H5</td>
</tr>
</tbody>
</table>
</div>
<p>
(Note:
<code>level=1</code>
is effectively "merge into host outline without level shift" — same TOC behavior as level=2/3, but no demotion of the headings themselves. Rare but valid.)
</p>
<p>When demotion is requested and would push headings past H6, clamp to H6 with a build warning:</p>
<div class="rf-codeblock">
<pre data-language="shell"><code data-language="shell">Warning: expand "SPEC-023" at site/content/blog/example.md:24 — heading
demotion (level=4) would push 2 heading(s) past H6. Clamped to H6:
- "Acceptance criteria" (was H4, would be H7)
- "Out of scope" (was H4, would be H7)
Consider reducing level= or restructuring the source's heading depth.
</code></pre>
</div>
<p>
Demotion still applies only to
<code>heading</code>
nodes in the Markdoc tree, not to rune-emitted custom elements styled as headings.
</p>
<h3 id="SPEC-066--visual-treatment-is-theme-owned">Visual treatment is theme-owned</h3>
<p>
Two H1s on a page (the host's and the embed's) can look visually odd if a theme styles all H1s identically. Themes handle this by targeting
<code>.rf-expand h1</code>
,
<code>.rf-expand h2</code>
, etc. and applying an embedded-heading treatment (smaller scale, boxed, "quoted" styling). Lumina ships a default; theme authors can override. Critically, this is a
<em marker="*">presentation</em>
concern — the underlying markup keeps natural heading semantics, themes adjust the visual hierarchy.
</p>
<hr />
<h2 id="SPEC-066--cycle-detection">Cycle Detection</h2>
<p>
Each resolution maintains a stack of
<code>(type, id)</code>
tuples. When entering an
<code>expand</code>
resolution, push the resolving entity's
<code>(type, id)</code>
. When finishing, pop. If pushing would create a duplicate, fail with the cycle path:
</p>
<div class="rf-codeblock">
<pre data-language="shell"><code data-language="shell">Error: expand cycle detected.
Cycle: SPEC-023 (spec) → WORK-051 (work) → SPEC-023 (spec)
Referenced from: site/content/blog/example.md:24
</code></pre>
</div>
<p>The stack is per-page-render, not global — embedding the same entity on two different pages is fine; embedding it inside itself transitively is the bug we catch.</p>
<p>
Self-references (
<code>{% expand "SPEC-023" /%}</code>
inside
<code>SPEC-023</code>
) are caught the same way: pushing SPEC-023 when SPEC-023 is already at the top of the stack.
</p>
<p>
<strong marker="**">
Note on
<code>{% ref %}</code>
inside embedded content
</strong>
: refs are
<em marker="*">links</em>
, not
<em marker="*">expansions</em>
. They don't push onto the resolution stack; they just resolve to a URL during postProcess. SPEC-023's body can
<code>{% ref "ADR-007" /%}</code>
and ADR-007's body can
<code>{% ref "SPEC-023" /%}</code>
back without any cycle concern. Only
<code>expand</code>
participates in cycle detection.
</p>
<hr />
<h2 id="SPEC-066--plugin-extractor-api">Plugin Extractor API</h2>
<p>
For an entity to be embeddable, its plugin must register the entity with two additional fields beyond the existing
<code>EntityRegistration</code>
shape:
</p>
<div class="rf-codeblock">
<pre data-language="ts"><code data-language="ts">interface EmbeddableEntityRegistration extends EntityRegistration {
sourceFile: string; // project-root-relative path
extract: (parsed: Markdoc.Node) => Markdoc.Node | null;
}
</code></pre>
</div>
<ul>
<li>
<strong marker="**">
<code>sourceFile</code>
</strong>
— project-root-relative path to the source file. Used by expand for the file read; sandbox rules apply.
</li>
<li>
<strong marker="**">
<code>extract</code>
</strong>
— given the parsed Markdoc AST of
<code>sourceFile</code>
, return the subtree to substitute. Returns null if the entity can't be located (treated as a build error by expand).
</li>
</ul>
<p>
Both fields are optional from the existing
<code>EntityRegistration</code>
interface's perspective — entities without them are simply not embeddable. Pages (registered by core), headings (registered by core), and any other registry contributors that don't add these fields will fail expand with the standard "does not support embedding" error.
</p>
<h3 id="SPEC-066--extractor-patterns">Extractor patterns</h3>
<ul>
<li>
<strong marker="**">One entity per file</strong>
(plan, certain worldbuilding plugins): extractor walks the parsed AST for the top-level rune tag matching the entity's type. Trivial.
</li>
<li>
<strong marker="**">Multiple entities per file</strong>
(e.g. a character-list page defining several characters): extractor walks for the rune tag whose
<code>id</code>
attribute matches the entity's ID. Plugin's job to manage uniqueness.
</li>
<li>
<strong marker="**">Composite entities</strong>
: a plugin can return an arbitrarily-shaped Markdoc subtree. expand doesn't constrain the structure.
</li>
</ul>
<hr />
<h2 id="SPEC-066--engine-changes">Engine Changes</h2>
<h3 id="SPEC-066--registry-interface">Registry interface</h3>
<p>
<code>packages/types/src/registry.ts</code>
(or
<code>EntityRegistry</code>
type definition): the
<code>EntityRegistration</code>
interface gains optional
<code>sourceFile</code>
and
<code>extract</code>
fields. Plugins that opt in supply both; plugins that don't continue to register entities as before.
</p>
<h3 id="SPEC-066--resolver">Resolver</h3>
<p>
New module
<code>packages/runes/src/expand-resolve.ts</code>
, structurally similar to
<code>xref-resolve.ts</code>
. Walks the page's renderable tree looking for
<code>data-rune="expand"</code>
placeholders, performs the resolution chain above, substitutes content.
</p>
<h3 id="SPEC-066--rune-schema">Rune schema</h3>
<p>
New file
<code>packages/runes/src/tags/expand.ts</code>
, following xref's two-phase pattern: transform emits a placeholder span; postProcess resolves and substitutes.
</p>
<h3 id="SPEC-066--core-pipeline-hooks">Core pipeline hooks</h3>
<p>
<code>packages/runes/src/index.ts</code>
—
<code>corePipelineHooks</code>
gains an expand-resolution step in postProcess, ordered after xref (so embedded refs can be resolved within the substituted content) or before (so refs in the host page resolve first).
<strong marker="**">Open question</strong>
— see below.
</p>
<h3 id="SPEC-066--css">CSS</h3>
<p>
<code>packages/lumina/styles/runes/expand.css</code>
: minimal styling for the wrapper and canonical-link affordance. The substantive content is styled by whichever rune is embedded (plan, character, etc.).
</p>
<hr />
<h2 id="SPEC-066--acceptance-criteria">Acceptance Criteria</h2>
<ul>
<li data-checked="unchecked">
<code>{% expand "SPEC-023" /%}</code>
substitutes the referenced entity's source content into the host page
</li>
<li data-checked="unchecked">Resolution chain: registry exact-ID → registry name → embeddability check → unresolved</li>
<li data-checked="unchecked">Unresolved IDs fail the build with closest-match suggestions (Levenshtein ≤ 2)</li>
<li data-checked="unchecked">
Entities without
<code>sourceFile</code>
+
<code>extract</code>
produce a "does not support embedding" build error
</li>
<li data-checked="unchecked">Page entities (registered by core) cannot be expanded — produce the not-embeddable error</li>
<li data-checked="unchecked">
<code>type</code>
attribute constrains registry lookup to the named type
</li>
<li data-checked="unchecked">
<code>sourceFile</code>
is read with the same sandbox rules as snippet (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-062">SPEC-062</span>
); traversal escape rejected
</li>
<li data-checked="unchecked">Source-file content is cached per build (multiple expands of entities from the same file = one parse)</li>
<li data-checked="unchecked">Extractor returning null fails the build with "extractor returned no content"</li>
<li data-checked="unchecked">
Embedded heading levels are preserved by default (no demotion when
<code>level=</code>
is unset)
</li>
<li data-checked="unchecked">
expand wrapper carries
<code>data-outline-scope="{entityId}"</code>
<strong marker="**">
only when
<code>level=</code>
is unset
</strong>
(peer-document mode)
</li>
<li data-checked="unchecked">
When
<code>level=</code>
is set,
<code>data-outline-scope</code>
is not emitted; the embed participates in the host outline as authored sub-content
</li>
<li data-checked="unchecked">
The neutral
<code>data-outline-scope</code>
convention is consumed by two generic walkers, not by expand-specific code
</li>
<li data-checked="unchecked">
Heading-ID walker prefixes IDs of headings inside any
<code>data-outline-scope</code>
subtree with
<code>{scope-value}--</code>
(e.g.,
<code>SPEC-023--acceptance-criteria</code>
)
</li>
<li data-checked="unchecked">
When
<code>level=</code>
is set, heading IDs go through the normal slugifier (no prefix); ID collisions with host headings become the author's responsibility (caught by future heading-uniqueness lint, not by expand)
</li>
<li data-checked="unchecked">Heading IDs use the standard slugifier for the suffix portion (peer mode) or the full ID (sub-section mode)</li>
<li data-checked="unchecked">
TOC walker (used by
<code>{% toc %}</code>
and similar tooling) skips headings descended from any element with
<code>data-outline-scope</code>
set, regardless of which rune set it
</li>
<li data-checked="unchecked">
When
<code>level=</code>
is set, embedded headings appear in the host TOC at their demoted level
</li>
<li data-checked="unchecked">
<code>level=N</code>
attribute opts into explicit demotion: headings shift by
<code>N - 1</code>
while preserving relative hierarchy
</li>
<li data-checked="unchecked">Demoted headings clamped at H6 emit a build warning naming source location and affected heading text</li>
<li data-checked="unchecked">
Lumina ships a default heading treatment for
<code>.rf-expand h1</code>
/
<code>h2</code>
/etc. that visually distinguishes embedded headings without altering their semantic level
</li>
<li data-checked="unchecked">
Cycle detection:
<code>(type, id)</code>
stack tracks open expansions; duplicate push fails with cycle path
</li>
<li data-checked="unchecked">
Refs (
<code>{% xref %}</code>
/
<code>{% ref %}</code>
) inside embedded content do not participate in cycle detection
</li>
<li data-checked="unchecked">
Output wrapper has
<code>.rf-expand</code>
class with
<code>data-rune</code>
,
<code>data-entity-id</code>
,
<code>data-entity-type</code>
,
<code>data-canonical-href</code>
,
<code>data-source="registry"</code>
</li>
<li data-checked="unchecked">
<code>data-canonical-href</code>
on the wrapper is populated whenever the xref chain resolves, regardless of the
<code>canonical</code>
attribute value
</li>
<li data-checked="unchecked">
<code>canonical=true</code>
renders a visible
<code>.rf-expand__canonical-link</code>
<code><a></code>
element
</li>
<li data-checked="unchecked">
<code>canonical=false</code>
(default) does not render a visible link element
</li>
<li data-checked="unchecked">
<code>.rf-expand__canonical-link</code>
href resolves via the xref chain (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-065">SPEC-065</span>
)
</li>
<li data-checked="unchecked">
When
<code>canonical=true</code>
and the URL is unresolved, the link element renders with
<code>rf-xref--unresolved</code>
styling (preserving the affordance while signaling the resolution gap)
</li>
<li data-checked="unchecked">Refs and other runes within the substituted content resolve normally via the host page's pipeline</li>
<li data-checked="unchecked">
Composes with drawer (
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-060">SPEC-060</span>
) —
<code>{% drawer %}{% expand %}{% /drawer %}</code>
works end-to-end
</li>
<li data-checked="unchecked">
Composes with
<code>{% expand %}</code>
on its own (no drawer) in any host context
</li>
<li data-checked="unchecked">
Lumina ships baseline
<code>.rf-expand</code>
+
<code>.rf-expand__canonical-link</code>
CSS
</li>
<li data-checked="unchecked">
<code>EntityRegistration</code>
interface gains optional
<code>sourceFile</code>
and
<code>extract</code>
fields with documented semantics
</li>
<li data-checked="unchecked">
Authoring docs cover the rune, the no-demotion default, heading ID namespacing, the optional
<code>level=</code>
opt-in, the TOC isolation behavior, and the relationship to xref / partial / embed
</li>
</ul>
<hr />
<h2 id="SPEC-066--out-of-scope">Out of Scope</h2>
<ul>
<li>
<strong marker="**">Page-entity embedding</strong>
. Falls out of the implicit-embeddability design: core doesn't register pages with extractors. If "embed a whole page" becomes a real need, address it with a different primitive (page-embed with explicit layout-region handling) rather than overloading expand.
</li>
<li>
<strong marker="**">Remote source fetching</strong>
(HTTP, github://, etc.). File system only. Heavy infrastructure (caching, network policy, build determinism) belongs in its own design.
</li>
<li>
<strong marker="**">Multi-entity expansion</strong>
(
<code>{% expand "SPEC-023,SPEC-024" /%}</code>
). Use multiple
<code>{% expand %}</code>
runes.
</li>
<li>
<strong marker="**">Cherry-picking sections</strong>
of an entity ("just the Acceptance Criteria of SPEC-023"). The extractor returns one subtree; partial extraction is a plugin-by-plugin concern, not a generic rune attribute.
</li>
<li>
<strong marker="**">Lazy / deferred expansion</strong>
at render time (vs. build time). Build-time only.
</li>
<li>
<strong marker="**">Inline editing</strong>
of embedded content. Read-only by construction.
</li>
<li>
<strong marker="**">Constructing a separate header / status display</strong>
in expand itself. The embedded rune renders its own header; expand adds only the wrapper + canonical-link.
</li>
<li>
<strong marker="**">Density modes / summary rendering</strong>
. Different presentation densities are a per-rune concern — if plan runes (or any other) want to support a summary mode, that's their feature, not expand's.
</li>
<li>
<strong marker="**">Backlinks / "where is this expanded from?"</strong>
. Out of scope; future site-graph concern.
</li>
<li>
<strong marker="**">Cross-site embedding</strong>
in multi-site monorepos. Each site sees its own registry. Future spec if demand surfaces.
</li>
</ul>
<hr />
<h2 id="SPEC-066--open-questions">Open Questions</h2>
<p>
<strong marker="**">Should the postProcess hook run expand before or after xref resolution on the host page?</strong>
Two cases to consider:
</p>
<ul>
<li>expand runs first → refs inside the substituted content are seen by xref's pass on the host page, so they resolve uniformly with everything else. Cleaner mental model.</li>
<li>xref runs first → refs in the host page are resolved before any embeds happen, but embedded content's refs would need a second xref pass after expand to be resolved. Worse: now there are two resolution rounds.</li>
</ul>
<p>
Recommend
<strong marker="**">expand first, xref second</strong>
. Single resolution pass for refs, regardless of whether they live in original or substituted content.
</p>
<p>
<strong marker="**">
What should the
<code>canonical=true</code>
link show when the URL is unresolved?
</strong>
Options: (a) omit the link entirely (treat as
<code>canonical=false</code>
); (b) render with
<code>rf-xref--unresolved</code>
styling (visible but not clickable); (c) show as plain text with the entity ID. Current recommendation is (b) — preserves the affordance's existence (reader knows there's a canonical somewhere) while signaling the resolution gap. Authors who'd rather suppress entirely can leave
<code>canonical=false</code>
for that entity.
</p>
<p>
<strong marker="**">
Should there be a project-level config to flip the
<code>canonical</code>
default?
</strong>
A site that consistently wants canonical links visible might want to set it once rather than per-rune. Tempting but adds surface; first ship the per-instance attribute and revisit if real demand surfaces.
</p>
<p>
<strong marker="**">Should the wrapper include a "back to host" affordance</strong>
when the embed lives in a drawer or other framing context? Tempting but couples expand to context (drawer-aware vs not). Recommend no — let the framing context (drawer) provide its own close affordance.
</p>
<p>
<strong marker="**">
How does expand interact with the
<code>tint</code>
cascade?
</strong>
Embedded content might come from a plan file with no tint declaration; the host page has its own tint. Recommend: the embed inherits the host's tint at the substitution point. Plan-file authoring shouldn't need to think about tints; they're a presentation-layer concern of the consumer site.
</p>
<p>
<strong marker="**">
Should
<code>expand</code>
set
<code>data-source="pattern"</code>
or any indicator
</strong>
when the entity was found via name-match rather than exact ID match? Symmetric with xref's source attribute. Recommend yes for parity.
</p>
<p>
<strong marker="**">Performance: source-file caching across pages.</strong>
If one source file (
<code>plan/specs/SPEC-023-foo.md</code>
) is expanded on twenty different pages, we want to parse it once, not twenty times. Per-build cache keyed by
<code>sourceFile</code>
handles this — same as snippet's caching.
</p>
<p>
<strong marker="**">Build-time vs. content-load-time extraction.</strong>
Could the plugin's
<code>extract</code>
be called once at content-load (when entities are registered) rather than per-expansion? It would let the registration store the pre-extracted AST and skip per-call extraction. Tradeoff: eager memory cost vs. lazy compute cost. Recommend lazy (per-expand call, but cached) — keeps memory bounded for projects with many registered entities that aren't all embedded.
</p>
<p>
<strong marker="**">
Should there be a
<code>lookup</code>
attribute
</strong>
to constrain resolution to exact-ID only (skip the name-match fallback)? Tempting for "fail fast on typos" use cases. Defer — xref doesn't have it either; consistent surface.
</p>
<hr />
<h2 id="SPEC-066--references">References</h2>
<ul>
<li>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-060">SPEC-060</span>
— drawer rune (primary composition target)
</li>
<li>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-064">SPEC-064</span>
— plan plugin unconditional entity registration (companion spec — the registration work that makes plan entities embeddable)
</li>
<li>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-065">SPEC-065</span>
— configurable xref resolution (used for canonical-link affordance)
</li>
<li>
<span class="rf-xref rf-xref--unresolved" data-xref-id="SPEC-062">SPEC-062</span>
— snippet rune (shared sandbox + source-caching machinery)
</li>
<li>
<code>packages/runes/src/tags/xref.ts</code>
— symmetric existing rune; expand mirrors its two-phase structure
</li>
<li>
<code>packages/runes/src/xref-resolve.ts</code>
— postProcess resolver pattern this spec follows
</li>
</ul>
</div>
</article>
<a class="rf-expand__canonical-link rf-xref--unresolved">View full spec source</a>
</section>
</div>
</section>canonical=true adds a link to the entity's own page after the content, for when the embed is a peek; label sets its text.
Fit the headings into the page
An embed is a quoted document, not a part of the host page. Its headings keep their levels, stay out of the page's table of contents, and their anchors are prefixed with the entity's ID (SPEC-066--acceptance-criteria), so they never clash with the page's own.
When the embed really is a subsection of the page, set level to the level its top heading should take. Its headings shift down to match and join the table of contents, with unprefixed anchors:
level= | H1 becomes | H2 becomes | In the table of contents |
|---|---|---|---|
| not set | H1 | H2 | no |
2 | H2 | H3 | yes |
3 | H3 | H4 | yes |
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
primary | string | ✓ | Entity ID or name to substitute inline. Same lookup chain as xref. |
level | number | — | Optional heading-demotion opt-in. When set, embedded headings shift by `N - 1` and the embed joins the host outline instead of staying TOC-isolated. |
type | string | — | Entity type hint for disambiguation when the same ID/name lives in multiple registries. |
canonical | boolean | — | When true, append a visible "View canonical" link pointing at the entity's canonical URL. |
label | string | — | Custom label for the canonical link (only meaningful when `canonical=true`). |
| Not available | Why |
|---|---|
| bg, dropcap, elevation, frame, inset, motion (reveal, stagger), prominence, reading, spacing, substrate, tint, width | this rune declares no universal attributes |