Repository navigation
fix(html-nav): generate heading anchors the way GitHub does - #115
Conversation
html_navigation.py collapsed runs of spaces, decoded entities before stripping tags, kept emphasis underscores and image alt text, and dropped combining marks. Valid links to GitHub's anchors failed (terms--conditions, a--b--c) and links to collapsed ones passed. github_heading_slug now mirrors GitHub's rule on the rendered text: lowercase, keep letters, marks, digits (decimal and letter numbers), connector punctuation, hyphens and spaces, and turn each space into a hyphen. Code-span text counts literally; images, tags, comments, emphasis markers and backslash escapes are handled before the filter. The masked copy still decides which lines are headings; the text now comes from the source line, which retires restore_heading_code and protect_inline_code_angles. Every expected value in tests/test_github_heading_slugs.py was read back from GitHub's Markdown API (mode=markdown) on 2026-10-23. Against github-slugger's 78 fixtures the remaining 7 differences are comparison artefacts (separate documents, edge spaces Markdown strips) or Unicode-version differences. Closes #102 Co-Authored-By: Claude Opus 5.5 <[email protected]>
4c656bd to
09b86e8
Compare
andy-zen-dev
left a comment
There was a problem hiding this comment.
Reviewed exact head 09b86e89c702e0c8891a9d53bde39b3214f4c336: all four changed files, the existing HTML navigation/fragment scanner, issue #102 acceptance, CONTRIBUTING.md and the new slug fixtures. No AGENTS.md exists at this head. The implementation preserves the masked-source gate for recognizing headings while deriving slug text from original ATX heading content; this addresses repeated spaces, HTML-entity/tag ordering, escaped punctuation, inline code, emphasis, combining marks, and duplicate suffixes. Tests cover the issue's reproduced mismatches and a previously false-positive dead fragment.
All five required jobs in Actions run 39920557540 succeeded (Python 3.11, 3.14, 3.14 Windows, Ubuntu/Windows action self-tests). I did not execute independent local tests or verify GitHub's Markdown API responses myself. The documented limitation to ATX headings and potential Unicode-version differences remains. No merge-blocking finding for the documented scope.
Reader problem and change
A maintainer who linked to a heading with the anchor GitHub actually generates got a red check, and a link GitHub would break passed.
html_navigation.pycollapsed runs of spaces, decoded entities before stripping tags, kept emphasis underscores and image alt text, and dropped combining marks.github_heading_slugnow applies GitHub's rule to the rendered heading text:What counts as text:
The masked copy still decides which lines are headings, so nothing inside code blocks counts. The text now comes from the source line. That retires
restore_heading_codeandprotect_inline_code_angles. The duplicate-suffix logic is unchanged; GitHub confirmsintro,intro-1,intro-2.Closes #102
Evidence
tests/test_github_heading_slugs.py, 24 headings plus duplicates and a comment case, was read back from GitHub's Markdown API on 2026-10-23 (gh api markdown -f mode=markdown,id="user-content-…"). It covers all rows of the issue's table, plus images (logo--here), emoji (emoji--party), NBSP, tabs, escapes andsnake_case.Verification
run-python--m-unittest,use-a-href-with-html, literal-suffix duplicates) still pass.Limitations
🤖 Generated with Claude Code