Skip to content

Fix empty 'On this page' menu caused by duplicate/empty heading IDs#352

Draft
simonhamp wants to merge 1 commit intomainfrom
fix-empty-on-this-page-menu
Draft

Fix empty 'On this page' menu caused by duplicate/empty heading IDs#352
simonhamp wants to merge 1 commit intomainfrom
fix-empty-on-this-page-menu

Conversation

@simonhamp
Copy link
Copy Markdown
Member

Summary

  • HeadingRenderer: Generate unique, non-empty heading IDs by tracking used IDs per conversion and suffixing duplicates (-1, -2, etc.). Empty slugs fall back to heading.
  • CommonMark: Reset heading ID tracking before each convertToHtml() call so IDs stay unique within a document but don't leak across conversions.
  • plugin-toc.blade.php: Defensively filter out headings with empty IDs and use a separate tocKey for Alpine's x-for :key to handle any remaining duplicates in pre-rendered HTML.

Test plan

  • Added test for duplicate headings getting unique IDs
  • Added test for empty slug fallback
  • Added test for ID reset between conversions
  • Existing heading renderer tests still pass
  • Verify on production plugin page that the "On this page" menu populates correctly

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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