Repository navigation
fix(blog): read heading ids from the rendered html - #137
Merged
Merged
Conversation
`parseMarkdownFile` computed the `headings` slugs from mdast, separately from the ids rehype-slug puts on the rendered headings, and the two disagreed. It joined only the direct `text` and `inlineCode` children with a space, so a heading containing inline code produced a doubled separator (`agent--に-ai-用の前提を集める` against the rendered `agent-に-ai-用の前提を集める`), a heading whose text sits inside a link or strong lost that text, and slugging only h2/h3 could put the dedupe counter out of step with rehype-slug. Collect the headings from the tree right after rehype-slug instead, so there is one source of truth. Nothing renders `headings` today, but anything that starts to would have linked to anchors that do not exist.
Skip headings with an empty id so the list matches what BlogToc builds from the DOM, reset the array at the start of the transformer so hoisting the processor cannot accumulate duplicates, and use the HeadingEntry type in the signatures that already described it inline. Also record two behaviours the switch to the rendered tree introduces: headings that come from raw HTML in the body are now included, and `title` is the text before KaTeX renders it, so a heading containing math reports its source rather than the rendered markup. Tests cover the raw HTML and empty id cases.
iamtatsuki05
marked this pull request as ready for review
September 21, 2026 05:10
Merged
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.
WHY
Follow-up noted in #135.
parseMarkdownFilecomputed theheadingsslugs from mdast, separately from the idsrehype-slugputs on the rendered headings, and the two disagreed.For the bonsai post:
Three ways it drifted:
textandinlineCodechildren with a space, so a heading containing inline code gained a doubled separator**strong**lost that text entirelyrehype-slugslugs every heading, so the dedupe counter could fall out of step (## Notesunder# Notesisnotes-1in the html)Nothing renders
headingstoday — the table of contents reads the DOM — so there is no visible bug. But anything that starts using the field would link to anchors that do not exist, and it is adjacent to thelegacyAnchorsmap added in #135, where copying a slug from here would produce a confusing build failure.WHAT
rehype-slugwith a smallcollectHeadingsplugin, so the ids come from the same place the html doesgithub-sluggerand mdast type imports it needed**strong**VERIFICATION
bun run build(73 pages), Playwright chromium E2E 59 — all passheadingsvalues move