fix: derive heading anchors from plain text, not rendered HTML#314
Merged
Conversation
The heading() renderer was hashing the already-HTML-rendered heading content to produce its anchor id. For headings containing inline code, the syntax highlighter wraps the code in <code><span style="..."> markup, which then got slugified into anchor ids like #array-givens-and-code-class-language-malloy-style-...-span- Walk the Markdown AST to extract plain text first, then slug it. The displayed heading still uses the full rendered HTML; only the anchor id and in-page href use the plain-text slug. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Headings containing inline code were producing anchor ids that included the syntax-highlighter's full HTML markup. Example before:
render_document.ts:heading()was hashing the rendered HTML version of the heading content. This change walks the Markdown AST to extract plain text first, then slugs that. The displayed heading still uses the full rendered HTML — only the anchorid(and matchinghref) use the plain-text slug.After the fix, the example heading becomes
#array-givens-and-in.Impact on existing links
I grep'd every authored
(#anchor)link insrc/: all of them already use clean slugs (#finalizing-givens-at-the-runtime,#accepted-js-shapes, etc.). They were broken under the old generator whenever they pointed at a header containing inline code; this change makes them resolve correctly. No source-side fixups are needed.External bookmarks or third-party links pointing at the old junk anchors would no longer resolve, but those URLs weren't usable to begin with — they were never the canonical form an author would have written.
Test plan
npm run buildsucceeds.#array-givens-and-inresolves to the heading. (Verified locally.)setup/config.malloynb,experiments/givens.malloynb— and confirm their anchors look clean and in-page links work.🤖 Generated with Claude Code