Repository navigation
fix(core): never render headings inside component children - #524
Merged
Merged
Conversation
A `#`…`######` line inside a callout, card, tab, accordion, step or GitHub alert became a real h1–h6 with an anchor link, and h2–h4 also got a table-of-contents entry. That put a second h1 on the page, and a heading in a hidden tab or a collapsed accordion became a TOC link to content the reader could not see. The new remarkComponentHeadings plugin runs in the default remark stack after remarkDirectiveToMdx and turns every heading under a component element into a paragraph that keeps its inline content. Headings outside components, including those in a plain blockquote, are unchanged. The extract test that expected a directive heading in the TOC now expects it to be skipped. The flame search indexer follows the same rule: a heading inside a container directive is indexed as content of the enclosing section instead of as its own section, a heading marker in an alert line is stripped from the indexed text, and the `:::` fence lines themselves are no longer indexed as text.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Mode: standard. Reviewed the single commit that stops components from rendering headings among their children. It changes the core remark stack, the flame search indexer, the tests and the docs.
remarkComponentHeadings— a new remark plugin, placed last increateDefaultRemarkPlugins(). It rewrites everyheadingunder anmdxJsxFlowElementinto aparagraph, so callouts, cards, tabs, accordions, steps and GitHub alerts produce no h1–h6, no anchor and no TOC entry.- TOC parity —
extractTocsFromRawMdx(coreextract.ts) and flamecompileMdx(mdx.ts) both build on the default stack. That means the rendered HTML,rehypeCollectTocsand the raw TOC extraction all apply the same rule. - Search indexer —
extractRecordstrackscomponentDepthfrom:::nameand:::fences. A heading inside a component becomes a standalone content record under the enclosing section. Fence lines are no longer indexed.#markers on alert and blockquote lines are stripped. - Contract update — the
extract.test.tscase from #373 now expects a heading inside a directive to be left out of the TOC. - Docs and release — adds a "No headings inside components" section in
formatting.mdx, updates the core README rows, and adds a patch changeset for@docubook/coreand@docubook/flame.
Overall assessment: ready to merge. I found no CRITICAL, HIGH or MEDIUM issues.
What I checked:
- Cache invalidation:
cache-key.tsalready includes.docu/node/search-indexer.tsin its key material, andrenderToolchainStamp()folds in the built@docubook/*packages. Existing caches are therefore invalidated without aBUILD_CACHE_VERSIONbump. - Unbalanced fences: if
::::arrives while an inner:::tabis still open, micromark closes only the inner container, and the outer one runs to the end of the document. The indexer's depth count also stays above 0 in that case, so the search index matches what is rendered instead of drifting from it. - Components that depend on child headings: no component in
@docubook/markdownreads headings from its children, so changing them to paragraphs changes no component's behavior.
claude-opus-5-5 | 𝕏
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.

Summary
A component never renders an
<h1>–<h6>among its children now. Before this change, a#…######line inside a callout, card, tab, accordion, step or GitHub alert became a real heading with an id and an anchor link, and h2–h4 also got a table-of-contents entry. That broke the page contract in three ways:# H1inside a component put a second<h1>on the page, next to the frontmatter title the layout already renders.hidden) became a TOC link to content the reader could not see. Clicking it did not scroll, and the tab or accordion did not open.## Installadded#installand#install-1to the TOC, and one of them always pointed at a hidden panel.Change
remarkComponentHeadings(new,packages/core/src/plugins/remarkComponentHeadings.ts) runs increateDefaultRemarkPlugins()afterremarkDirectiveToMdx. It turns every heading under anmdxJsxFlowElementinto a paragraph that keeps its inline content (bold, code, links). Directives and GitHub alerts are the only components in the v2mdpipeline, so this covers all of them. The plugin is also exported from@docubook/core.compileMdxin flame andextractTocsFromRawMdxuse the default remark stack, so the rendered HTML and the TOC follow the same rule.lvl2+record. Without this, the record's anchor would point at an id that no longer exists. A heading marker on an alert line (> ## …) is stripped from the indexed text. The:::nameand:::fence lines are no longer indexed as text.extract.test.tshad a case that expected a heading inside:::notein the TOC (from fix: compile TOCs from rendered headings and harden directive fallbacks #373). That was the old contract, so the test now expects the heading to be skipped.getting-started/formatting.mdx, and the plugin inpackages/core/README.md.@docubook/coreand@docubook/flame.No page in the docs site or the template has a heading inside a directive, so no rendered docs page changes.
Known limit
Flame appends user remark plugins after the default stack. A user plugin that inserts a heading into a component element on purpose is not rewritten. Authored content always follows the rule.
Verification
remarkComponentHeadings.test.tscompiles every level, h1–h6, inside callouts, cards, tabs, accordions, steps and GitHub alerts. It asserts that no heading is emitted and the text is kept, that inline markup survives as a paragraph, that headings outside components and in plain blockquotes stay headings, and that duplicate tab headings stay out of the TOC.component-headings.test.tsrunscompileMdx→renderToStaticMarkupon a page that mixes all component types. It asserts that the only heading in the HTML is the page's## Section, that each component heading renders as<p>…</p>, and that the TOC holds only that section. Before the fix, the same input rendered h1–h6 inside every component and listed them in the TOC.:::or###text in the records, and headings after a component indexed as sections again.@docubook/coretests (144) and@docubook/flametests (879) pass. Typecheck, oxlint and prettier are clean, and the pre-push build passed.