Skip to content

Fix list source maps including trailing blank lines - #1212

Open
dyk1454683243-sudo wants to merge 1 commit into
markdown-it:masterfrom
dyk1454683243-sudo:cursor/fix-list-sourcemap-374-ca80
Open

dyk1454683243-sudo wants to merge 1 commit into
markdown-it:masterfrom
dyk1454683243-sudo:cursor/fix-list-sourcemap-374-ca80

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

Fixes #374

Cause

The list rule sets bullet_list_open / ordered_list_open and list_item_open map[1] to the line where the rule terminates. That is the first line that cannot belong to the list (usually the next non-empty, less-indented block). Blank lines skipped after the last content are therefore included in the end row.

- aaa


bbb

bullet_list_open and list_item_open currently get [0, 3] instead of [0, 1]. Paragraphs and other block tokens already stop at the last content line.

Fix

Trim trailing empty lines from list and list_item maps only. state.line is left unchanged so tightness, nesting, and HTML output stay the same.

Tests

Added test/markdown-it/list-sourcemap.test.mjs for the issue case, ordered lists, tight multi-item lists, blanks after the last item, blanks between paragraphs in a loose item, nested lists, and unchanged HTML.

The list rule recorded map end at the first line that cannot belong to
the list, which includes blank lines after the last item. Trim trailing
empty lines from list and list_item maps only. Leave state.line unchanged
so tightness and HTML stay the same.

Fixes markdown-it#374

Co-authored-by: David <[email protected]>
@puzrin

puzrin commented Sep 20, 2026

Copy link
Copy Markdown
Member

This branch has not been deployed

No deployments
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.

list sourceMap end row includes trailing blank lines

3 participants