Repository navigation
fix(markdown): include setext headings in the document outline - #391
Merged
petertzy merged 3 commits intoOct 8, 2026
Merged
Conversation
The outline endpoint only scanned ATX (#) headings, so sections written as 'Title' + '====' underlines were anchored by the preview but missing from the outline and its table of contents. Scan for CommonMark setext underlines too (matching the renderer: '=' -> h1, two or more '-' -> h2, backtick fences skipped) and merge both heading kinds in source order.
Owner
|
Approved — this is a necessary correctness fix. The outline now includes CommonMark Setext headings in source order and produces the same anchors as the preview renderer, while preserving exclusions for thematic breaks and fenced code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
/api/markdown/outlineendpoint only scanned ATX (#) headings, but the preview renderer also anchors CommonMark setext headings:Title+=====→<h1 id="title">Sub+-----→<h2 id="sub">So whole sections were visible and linkable in the preview yet silently missing from the outline panel and its table of contents.
Fix
Add a fence-aware setext scan in the outline extractor that mirrors the renderer exactly:
=underlines become level 1, two-or-more-underlines become level 2, blank-line-separated underlines stay thematic breaks, backtick fences are skipped, and an ATX heading line never double-counts. Both heading kinds are merged in source order.Tests
tests/test_markdown_outline.py: setext level-1/2 nodes with correct anchors and line numbers, outline anchors == rendered anchor ids, plus thematic-break and fenced-code exclusions.