Skip to content

Conversation

@xihale
Copy link

@xihale xihale commented Dec 4, 2025

This PR improves Table of Contents (TOC) generation to correctly handle documents that start with H2 (or lower) headers, and optimizes the parsing logic.

Close: #186

Changes

src/render/html.zig

  • Auto-detect Root Level: The TOC generator now scans for the minimum heading level (min_level) in the document and uses that as the root.
  • No Output for Empty TOC: Returns early if no headings are found, preventing empty <ul></ul> tags.

Tests

  • Added tests/rendering/toc_bug/ reproduction case.
    • Input: index.smd with only H2 headers.
    • Output: snapshot/toc/index.html confirms a flat <ul> list without nested empty items.

Breaking

Before, detecting whether a toc is empty we use $page.toc().len().gt(10), but now we use $page.toc().len().gt(0).

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.

Toc rendering is not clean enough

1 participant