feat: heading <section> wrapping (P1.2) - #16
Merged
Conversation
Implements grammar PART 9 §13 (carve PR #18). renderHtml now does a stateful section-wrapping pass over top-level blocks: every heading opens a <section id="{slug}"> holding the heading and the content up to the next same-or-shallower heading. The id moves from the <h*> to the <section>; sections nest by heading level. - Adjacent same-level headings -> sibling sections. - Skipped levels nest by number (# H1 / ### H3 -> h3-section two deep). - Explicit {#id} on a heading goes to <section>; other heading attrs (classes, key-values) stay on <h*>. - No-heading / empty docs emit zero <section>s. - Nested headings inside containers are not top-level, carry no id, and stay bare <h*> (resolveHeadingIds only assigns ids to top-level). - Fragment URLs (#slug), </#id> crossrefs, and [Heading][] implicit refs all keep working -- only the id emission site moved. Matches djot-php's renderDocumentWithSections shape. Tests: - New test/section-wrapper.test.ts (11 cases). - Updated heading-ids + implicit-heading-refs assertions to the new section shape. - 6 heading corpus fixtures (02-headings*, 17-attributes, 19-heading-ids) temporarily added to KNOWN_GAPS: the impl is now ahead of the vendored spec corpus, which still encodes the bare-<h*> shape. They are re-added once the carve repo re-vendors carve-lib and rewrites those fixtures, then bumps the spec submodule here. 222 tests pass + 6 todo; typecheck clean.
This was referenced May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Impl side of carve PR #18 (grammar PART 9 §13). Adopts djot's
<section>wrapper around headings.Behavior
renderHtmlnow does a stateful section-wrapping pass over top-level blocks. Every heading opens a<section id="{slug}">holding the heading and the content up to the next same-or-shallower heading. The id moves from the<h*>to the<section>; sections nest by heading level.→
Rules
# H1 / ### H3→ h3-section two levels deep, no synthesized h2).{#id}on a heading goes to<section>; other heading attrs (classes, key-values) stay on<h*>.<section>s.<h*>—resolveHeadingIdsonly assigns ids to top-level headings.#slug),</#id>cross-references, and[Heading][]implicit references all keep working — only the id emission site moved. Browsers resolve#slugto whichever element carries the id.Mirrors djot-php's
renderDocumentWithSectionsshape.Tests
test/section-wrapper.test.ts(11 cases): single/nested/sibling/skip-level wrapping, explicit-id placement, no-heading + empty docs, end-of-doc closing, crossref fragment resolution, nested-heading-not-wrapped.heading-ids+implicit-heading-refsassertions to the section shape.02-headings*,17-attributes,19-heading-ids) temporarily added toKNOWN_GAPS: the impl is now ahead of the vendored spec corpus, which still encodes the bare-<h*>shape. They are re-added once the carve repo re-vendors carve-lib and rewrites those fixtures, then bumps the spec submodule here. Same coordination pattern as the ASCII-slug change (ASCII-safe heading id slugs (baked Unicode -> ASCII translit) #13 → chore: bump spec submodule (ASCII heading-ids corpus + new examples) #15).222 tests pass + 6 todo; typecheck clean.
Follow-up sequence
02-headings*/17-attributes/19-heading-idsfixtures to section shapeKNOWN_GAPSentries