Skip to content

fix: derive heading anchors from plain text, not rendered HTML#314

Merged
mtoy-googly-moogly merged 1 commit into
mainfrom
fix/heading-anchor-strip-formatting
May 13, 2026
Merged

fix: derive heading anchors from plain text, not rendered HTML#314
mtoy-googly-moogly merged 1 commit into
mainfrom
fix/heading-anchor-strip-formatting

Conversation

@mtoy-googly-moogly
Copy link
Copy Markdown
Contributor

Summary

Headings containing inline code were producing anchor ids that included the syntax-highlighter's full HTML markup. Example before:

#array-givens-and-code-class-language-malloy-style-background-color-fbfbfb-span-class-line-span-style-color-001080-in-span-span-code-

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 anchor id (and matching href) 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 in src/: 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 build succeeds.
  • On the givens experiment page, #array-givens-and-in resolves to the heading. (Verified locally.)
  • Spot-check a few other pages with inline-code headers — e.g. setup/config.malloynb, experiments/givens.malloynb — and confirm their anchors look clean and in-page links work.

🤖 Generated with Claude Code

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>
@mtoy-googly-moogly mtoy-googly-moogly merged commit baebfbd into main May 13, 2026
5 checks passed
@mtoy-googly-moogly mtoy-googly-moogly deleted the fix/heading-anchor-strip-formatting branch May 13, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant