Skip to content

End setext headings on their underline in source positions - #661

Open
tsnee wants to merge 1 commit into
commonmark:masterfrom
tsnee:setext-heading-end-sourcepos
Open

tsnee wants to merge 1 commit into
commonmark:masterfrom
tsnee:setext-heading-end-sourcepos

Conversation

@tsnee

@tsnee tsnee commented Nov 13, 2026

Copy link
Copy Markdown

Fixes #659.

finalize took a setext heading's end position from the current line, as it does for the document and for a fenced code block, which is closed on its own fence line. A setext heading, though, is finalized only when the line after its underline is processed, so it ended on that line:

Input Before After
Foo\n---\nbar\n 1:1-3:3 1:1-2:3
Foo\n---\n\nbar\n 1:1-3:0 1:1-2:3
Foo\n---\r\nbar\n 1:1-3:3 1:1-2:3
Foo\n---\n 1:1-2:3 1:1-2:3

This removes the setext case from that branch, so the heading's end is computed from the previous line like other blocks. The last case, at the end of the document, already went through the end-of-input branch and is unchanged.

Adds source_pos_setext_heading to api_test with all four inputs; the first three fail without the fix. On macOS, ctest passes for a shared Debug build and for a static Debug build with -fsanitize=address,undefined, and make lint is clean.

🤖 Generated with Claude Code

finalize took a setext heading's end position from the current line,
as it does for the document and for a fenced code block closed by its
fence. But a setext heading is finalized only when the line after its
underline is processed, so it ended on that line: at the end of the
next paragraph's first line (3:3 for "Foo\n---\nbar\n"), or at column 0
of a following blank line. Compute its end like other blocks, from the
previous line.

Fixes commonmark#659.

Co-Authored-By: Claude Opus 5.5 <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.

Setext heading's end position is on the line after its underline

1 participant