Light DOM render contract
This is the implementation contract for issue #83. The migration is in progress. Do not adopt the output until native, runtime, V7 and UI isolation checks pass. There is one document-body format; the migration does not add a legacy mode.
Presentation identity
The render request requires presentation:
{"instance_id":"article-main","document_anchors":"canonical"}instance_id has 1–64 ASCII letters, digits, underscores or hyphens. The host selects a stable placement identifier and ensures that it is unique among the bodies on the page. Source parameters cannot set it. A renderer child scope adds .note-N; host identifiers cannot contain a period.
document_anchors is canonical for the main article and instance for embedded bodies, editor previews and messages. The render response echoes presentation. Source analysis and bundle analysis do not accept presentation and do not vary their cache identity by placement. Render caches include the complete presentation.
Core emits one direct .sevenmark root with data-sm-scope and data-sm-document-anchors, including for empty selected content. Runtime adopts and verifies that root. A declared nested root is a boundary even before its runtime mounts. Updating a body must preserve current-authority cancellation and must not adopt an unrelated root.
Document fragments
Source authors use logical anchor names. [anchor(installation)] publishes the canonical ID sm-a- followed by lowercase hexadecimal UTF-8 bytes. A copied canonical fragment in [[Page#sm-a-...]] decodes before canonicalization, so it round-trips without double encoding. Generated section IDs keep s-1.2 form. Anchor definitions cannot use the sm- namespace or a generated section ID. Invalid reserved fragments receive a diagnostic; they do not become raw IDs. The first definition of a named anchor wins within its document namespace. Repeated definitions do not emit another ID.
An instance DOM ID is sm-i-<hex(scope)>-<local-id>. This encoding prevents placement delimiter collisions. Heading and named-anchor local IDs are their canonical IDs. Footnote and other runtime IDs always use the instance namespace, including in a canonical article. Outline id identifies the actual element; outline path remains the logical section path. Nested include islands use internal .include-N ID namespaces and instance anchors. They do not declare new CSS roots: their CSS still belongs to the nearest actual body root. Their headings do not enter the outer outline.
Same-body navigation uses the actual instance ID. Cross-document wiki navigation uses the target's canonical fragment. External URL fragments remain external URL fragments. Canonical navigation paths and presentation identity are separate.
Footnote fragments
document_anchors controls headings and authored named anchors. Footnotes belong to the containing body, including notes from its included documents. Their collection and named-note deduplication remain shared while include islands enter and leave their own document namespaces. Footnote references and deferred lists therefore use the same body instance namespace in both anchor modes.
For example, instance main uses sm-i-6d61696e-rn1 and sm-i-6d61696e-fn1 in both modes. Hosts keep the placement identifier stable, so a copied emitted footnote URL can survive reloads. Hosts and runtimes resolve the emitted ID/href pair; they must not strip or reconstruct the prefix.
A logical wiki link such as [[Page#fn1]] names an authored anchor. It does not select numbered footnote 1. Authors can define a named anchor in the document or its footnote and link to that name. Shortening generated footnote IDs alone does not add logical links to numbered footnotes.
CSS ownership
For root selector S = [data-sm-scope="<checked scope>"], a matching element must be either S or a descendant of S, and must not be a nested declared root or its descendant. The sanitizer adds this zero-specificity membership predicate to every selector compound and recursively handles functional selector lists. It preserves combinators and does not expand selector-list products. Root aliases refer to this body root. Generated style rules use the same ownership boundary. Native authored and generated rules also use an exact body @scope, ending at nested declared roots. This matches the runtime stylesheet's scoping proximity, so normal specificity and source order govern authored overrides. Compound guards remain required for selector operands. Dark rules put the theme scope outside this body scope. Wrapper bytes count toward the existing stylesheet output limit.
The sanitizer retains its current property, value and at-rule restrictions. Selector expansion is charged before guard allocation and fails closed at the existing stylesheet output budget. An exhausted rewrite never emits unscoped CSS. Native capabilities expose the actual sanitizer input/output byte, lexical-depth and rule-depth limits per block. Selector and admission drops produce typed coarse warnings during sanitization. A shared context deduplicates warning code plus host-projected span, including repeated footnote style discovery. Included CSS uses the honest host include-call range, while static pre-flatten diagnostics retain physical dependency ranges. LSP uses a read-only checker from HTML to reuse this exact policy with a checked dummy presentation. It reports unsupported selectors and syntax only, never dummy-scope budget predictions.
The UI must independently exclude every declared body from application CSS, including utility, component and asynchronous styles. It must also prevent host relational selectors from consulting authored descendants. Arbitrary authored classes must not activate trusted positioning or overlay rules. The shared, versioned runtime stylesheet is a separate trusted body stylesheet. Themes belong to the nearest explicit declared-body theme, with html[data-sm-theme] as the fallback. The UI owns that HTML attribute, including the existing prepaint script. A root without its own marker inherits the nearest explicit theme. Trusted dark rules use @scope (html[data-sm-theme="dark"], [data-sm-scope][data-sm-theme="dark"]) to ([data-sm-scope][data-sm-theme]). An explicit nested root stops the ancestor theme scope; a dark nested root starts its own. Authored CSS cannot consult host ancestors. Widget-only shadow roots may remain inside body content.
Adoption checks
The native renderer uses render protocol 7. Native, runtime, LSP and standalone formatter packages have independent versions and source records. LSP initialize responses report the actual LSP crate version. Each host must admit the exact package contents and producer identity that it tested.
- Native and real-browser tests cover sibling bodies, nested unmounted bodies, root aliases, functional selectors, nesting, pseudo-elements and bounded output.
- Browser checks prove isolation from host utilities and late stylesheet chunks.
- Main, preview, note and repeated-message IDs, links, ARIA references, and native fragment navigation stay coherent before and after runtime adoption.
- Missing and forbidden content remains publicly indistinguishable. Stale async work cannot restore removed identity, navigation or media authority.
- The accepted archive pins the native contract, runtime and actual LSP package. Parser or formatter changes require a new actual LSP package when they affect the editor; package version changes alone are not validation.