Skip to content

ndg-commonmark: align TOC anchors with heading ids for escaped markup#218

Merged
NotAShelf merged 1 commit into
feel-co:mainfrom
KiaraGrouwstra:fix-heading-id-decode-entities
Jun 3, 2026
Merged

ndg-commonmark: align TOC anchors with heading ids for escaped markup#218
NotAShelf merged 1 commit into
feel-co:mainfrom
KiaraGrouwstra:fix-heading-id-decode-entities

Conversation

@KiaraGrouwstra

Copy link
Copy Markdown
Contributor

Encodes HTML entities in heading ids in the TOC anchors to unbreak jump-to-header for headers with auto ids based on HTML entities in their content (e.g. .<name>).

This solution intentionally preserves the current (uglier) auto-ids (rather than resolving the gap the other way around) to prevent existing deep-links from breaking.

Closes #217.

Disclaimer: I used a coding agent in the creation of this patch.

@NotAShelf NotAShelf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, and thank you for the agent disclosure! I've left one quick note, which is not a blocker, and completely optional to address.

If you could just add a CHANGELOG entry under 2.9.0 # Fixes section, we'll be golden.

Comment thread ndg-commonmark/src/processor/core.rs Outdated
@KiaraGrouwstra KiaraGrouwstra force-pushed the fix-heading-id-decode-entities branch 2 times, most recently from 93be656 to be3e451 Compare June 2, 2026 05:50
@NotAShelf NotAShelf changed the title fix: align TOC anchors with heading ids for escaped markup ndg-commonmark: align TOC anchors with heading ids for escaped markup Jun 2, 2026
@NotAShelf

Copy link
Copy Markdown
Member

There seems to be a failing test, could you fix it before I can merge?

Headings whose text contains markup characters (e.g. an option named
`environments.<name>.deployment`) had a table-of-contents anchor that did not
match the heading's `id`, so "jump to header" landed nowhere.

The auto-generated heading `id` slugifies the *rendered* HTML, in which comrak
has escaped the brackets to `environments.&lt;name&gt;.deployment`, giving
`environments--lt-name-gt--deployment`. The table-of-contents slugified the raw
inline text instead, giving a different slug.

Close the gap on the table-of-contents side via a new `slugify_heading` helper
that escapes the text the same way comrak does before slugifying. The heading
`id` is left unchanged so existing deep links keep resolving. Adds a regression
test asserting the TOC anchor matches the rendered heading `id`.

Assisted-by: Claude:claude-opus-4-8
@KiaraGrouwstra KiaraGrouwstra force-pushed the fix-heading-id-decode-entities branch from be3e451 to 194f146 Compare June 2, 2026 16:04
@KiaraGrouwstra

Copy link
Copy Markdown
Contributor Author

Thanks for the heads-up! I updated that test to match this change as well now.

@NotAShelf NotAShelf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight installation--amp--setup is probably not the most intuitive heading ID, but I don't think this is a reason to block this PR any further. I'll pinpoint the semantics once I have a little bit more free time. Thank you for your good work, LGTM

@NotAShelf NotAShelf merged commit da7f8e2 into feel-co:main Jun 3, 2026
13 checks passed
@KiaraGrouwstra

Copy link
Copy Markdown
Contributor Author

i agree! and the original reconciliation i found was in fact to just add a decode_html_entities call to the id generator.
i didn't have a great sense tho of to what extent deep-links to ndg-generated documentation might be out there already - so for an initial fix i figured i'd play it safe there, while leaving the design decision for such a breaking change up to y'all to call.

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.

jump-to-header broken for headers containing HTML entities

2 participants