Skip to content

fix: render module doc body before examples in TOC#792

Open
crowlKats wants to merge 2 commits intomainfrom
fix/toc-heading-order
Open

fix: render module doc body before examples in TOC#792
crowlKats wants to merge 2 commits intomainfrom
fix/toc-heading-order

Conversation

@crowlKats
Copy link
Copy Markdown
Member

Summary

  • Fix table of contents ordering for module pages with both markdown body and @example tags
  • The page renders the markdown body (README) before the Examples section, but the TOC entries were added in reverse order, causing README headings to appear after Examples entries
  • Additionally, the shared offset state from add_entry inflated README heading levels when examples were present, nesting them too deeply

Closes jsr-io/jsr#486

Test plan

  • Added readme_toc_order_with_examples test that verifies README headings appear before Examples in the TOC
  • All existing tests pass without snapshot changes

🤖 Generated with Claude Code

crowlKats and others added 2 commits April 3, 2026 22:21
The module doc body (README) is rendered before @example sections in the
page HTML, but the TOC entries were added in the opposite order. This
caused README headings to appear after Examples entries in the table of
contents, and the shared offset state inflated their nesting level.

Swap the order so jsdoc_body_to_html runs before jsdoc_examples, making
the TOC match the page layout.

Closes jsr-io/jsr#486

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The offset in HeadingToCAdapter is shared mutable state set as a side
effect of add_entry. Previously, render_markdown_inner read it lazily
inside the anchorizer closure, so any add_entry call before the markdown
was fully rendered could inflate heading levels.

Snapshot the offset at the start of render_markdown_inner so it is
immune to later mutations. This makes the heading level calculation
deterministic regardless of call ordering.

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.

UX: Last heading in README is first entry in table of contents

1 participant