-
-
Notifications
You must be signed in to change notification settings - Fork 954
refactor(markdown-parser): align newline/prescan paragraph-break checks #9197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ematipico
merged 5 commits into
biomejs:main
from
jfmcdowell:refactor/newline-prescan-parity
Mar 3, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2fed70
refactor(markdown-parser): extract at_paragraph_break predicate
jfmcdowell a6fa353
refactor(markdown-parser): add setext check after list indent in prescan
jfmcdowell 36558f1
refactor(markdown-parser): remove include_textual_markers parameter
jfmcdowell 57651cd
test(markdown): add quote textual-marker parity regression
jfmcdowell 1971de8
docs(markdown-parser): clarify paragraph-break rustdoc
jfmcdowell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
crates/biome_markdown_parser/tests/md_test_suite/ok/quote_textual_marker_parity.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| > paragraph line | ||
| > - nested bullet | ||
|
|
||
| > paragraph line | ||
| > 1. nested ordered | ||
|
|
||
| > paragraph line | ||
| > still paragraph |
203 changes: 203 additions & 0 deletions
203
crates/biome_markdown_parser/tests/md_test_suite/ok/quote_textual_marker_parity.md.snap
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| --- | ||
| source: crates/biome_markdown_parser/tests/spec_test.rs | ||
| assertion_line: 131 | ||
| expression: snapshot | ||
| --- | ||
|
|
||
| ## Input | ||
|
|
||
| ``` | ||
| > paragraph line | ||
| > - nested bullet | ||
|
|
||
| > paragraph line | ||
| > 1. nested ordered | ||
|
|
||
| > paragraph line | ||
| > still paragraph | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## AST | ||
|
|
||
| ``` | ||
| MdDocument { | ||
| bom_token: missing (optional), | ||
| value: MdBlockList [ | ||
| MdQuote { | ||
| marker_token: R_ANGLE@0..1 ">" [] [], | ||
| content: MdBlockList [ | ||
| MdParagraph { | ||
| list: MdInlineItemList [ | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@1..16 "paragraph line" [Skipped(" ")] [], | ||
| }, | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@16..17 "\n" [] [], | ||
| }, | ||
| ], | ||
| hard_line: missing (optional), | ||
| }, | ||
| MdBulletListItem { | ||
| md_bullet_list: MdBulletList [ | ||
| MdBullet { | ||
| bullet: MINUS@17..20 "-" [Skipped(">"), Skipped(" ")] [], | ||
| content: MdBlockList [ | ||
| MdParagraph { | ||
| list: MdInlineItemList [ | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@20..34 " nested bullet" [] [], | ||
| }, | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@34..35 "\n" [] [], | ||
| }, | ||
| ], | ||
| hard_line: missing (optional), | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| MdNewline { | ||
| value_token: NEWLINE@35..36 "\n" [] [], | ||
| }, | ||
| MdQuote { | ||
| marker_token: R_ANGLE@36..37 ">" [] [], | ||
| content: MdBlockList [ | ||
| MdParagraph { | ||
| list: MdInlineItemList [ | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@37..52 "paragraph line" [Skipped(" ")] [], | ||
| }, | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@52..53 "\n" [] [], | ||
| }, | ||
| ], | ||
| hard_line: missing (optional), | ||
| }, | ||
| MdOrderedListItem { | ||
| md_bullet_list: MdBulletList [ | ||
| MdBullet { | ||
| bullet: MD_ORDERED_LIST_MARKER@53..57 "1." [Skipped(">"), Skipped(" ")] [], | ||
| content: MdBlockList [ | ||
| MdParagraph { | ||
| list: MdInlineItemList [ | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@57..72 " nested ordered" [] [], | ||
| }, | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@72..73 "\n" [] [], | ||
| }, | ||
| ], | ||
| hard_line: missing (optional), | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| MdNewline { | ||
| value_token: NEWLINE@73..74 "\n" [] [], | ||
| }, | ||
| MdQuote { | ||
| marker_token: R_ANGLE@74..75 ">" [] [], | ||
| content: MdBlockList [ | ||
| MdParagraph { | ||
| list: MdInlineItemList [ | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@75..90 "paragraph line" [Skipped(" ")] [], | ||
| }, | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@90..91 "\n" [] [], | ||
| }, | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@91..108 "still paragraph" [Skipped(">"), Skipped(" ")] [], | ||
| }, | ||
| MdTextual { | ||
| value_token: MD_TEXTUAL_LITERAL@108..109 "\n" [] [], | ||
| }, | ||
| ], | ||
| hard_line: missing (optional), | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| eof_token: EOF@109..109 "" [] [], | ||
| } | ||
| ``` | ||
|
|
||
| ## CST | ||
|
|
||
| ``` | ||
| 0: MD_DOCUMENT@0..109 | ||
| 0: (empty) | ||
| 1: MD_BLOCK_LIST@0..109 | ||
| 0: MD_QUOTE@0..35 | ||
| 0: R_ANGLE@0..1 ">" [] [] | ||
| 1: MD_BLOCK_LIST@1..35 | ||
| 0: MD_PARAGRAPH@1..17 | ||
| 0: MD_INLINE_ITEM_LIST@1..17 | ||
| 0: MD_TEXTUAL@1..16 | ||
| 0: MD_TEXTUAL_LITERAL@1..16 "paragraph line" [Skipped(" ")] [] | ||
| 1: MD_TEXTUAL@16..17 | ||
| 0: MD_TEXTUAL_LITERAL@16..17 "\n" [] [] | ||
| 1: (empty) | ||
| 1: MD_BULLET_LIST_ITEM@17..35 | ||
| 0: MD_BULLET_LIST@17..35 | ||
| 0: MD_BULLET@17..35 | ||
| 0: MINUS@17..20 "-" [Skipped(">"), Skipped(" ")] [] | ||
| 1: MD_BLOCK_LIST@20..35 | ||
| 0: MD_PARAGRAPH@20..35 | ||
| 0: MD_INLINE_ITEM_LIST@20..35 | ||
| 0: MD_TEXTUAL@20..34 | ||
| 0: MD_TEXTUAL_LITERAL@20..34 " nested bullet" [] [] | ||
| 1: MD_TEXTUAL@34..35 | ||
| 0: MD_TEXTUAL_LITERAL@34..35 "\n" [] [] | ||
| 1: (empty) | ||
| 1: MD_NEWLINE@35..36 | ||
| 0: NEWLINE@35..36 "\n" [] [] | ||
| 2: MD_QUOTE@36..73 | ||
| 0: R_ANGLE@36..37 ">" [] [] | ||
| 1: MD_BLOCK_LIST@37..73 | ||
| 0: MD_PARAGRAPH@37..53 | ||
| 0: MD_INLINE_ITEM_LIST@37..53 | ||
| 0: MD_TEXTUAL@37..52 | ||
| 0: MD_TEXTUAL_LITERAL@37..52 "paragraph line" [Skipped(" ")] [] | ||
| 1: MD_TEXTUAL@52..53 | ||
| 0: MD_TEXTUAL_LITERAL@52..53 "\n" [] [] | ||
| 1: (empty) | ||
| 1: MD_ORDERED_LIST_ITEM@53..73 | ||
| 0: MD_BULLET_LIST@53..73 | ||
| 0: MD_BULLET@53..73 | ||
| 0: MD_ORDERED_LIST_MARKER@53..57 "1." [Skipped(">"), Skipped(" ")] [] | ||
| 1: MD_BLOCK_LIST@57..73 | ||
| 0: MD_PARAGRAPH@57..73 | ||
| 0: MD_INLINE_ITEM_LIST@57..73 | ||
| 0: MD_TEXTUAL@57..72 | ||
| 0: MD_TEXTUAL_LITERAL@57..72 " nested ordered" [] [] | ||
| 1: MD_TEXTUAL@72..73 | ||
| 0: MD_TEXTUAL_LITERAL@72..73 "\n" [] [] | ||
| 1: (empty) | ||
| 3: MD_NEWLINE@73..74 | ||
| 0: NEWLINE@73..74 "\n" [] [] | ||
| 4: MD_QUOTE@74..109 | ||
| 0: R_ANGLE@74..75 ">" [] [] | ||
| 1: MD_BLOCK_LIST@75..109 | ||
| 0: MD_PARAGRAPH@75..109 | ||
| 0: MD_INLINE_ITEM_LIST@75..109 | ||
| 0: MD_TEXTUAL@75..90 | ||
| 0: MD_TEXTUAL_LITERAL@75..90 "paragraph line" [Skipped(" ")] [] | ||
| 1: MD_TEXTUAL@90..91 | ||
| 0: MD_TEXTUAL_LITERAL@90..91 "\n" [] [] | ||
| 2: MD_TEXTUAL@91..108 | ||
| 0: MD_TEXTUAL_LITERAL@91..108 "still paragraph" [Skipped(">"), Skipped(" ")] [] | ||
| 3: MD_TEXTUAL@108..109 | ||
| 0: MD_TEXTUAL_LITERAL@108..109 "\n" [] [] | ||
| 1: (empty) | ||
| 2: EOF@109..109 "" [] [] | ||
|
|
||
| ``` |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prescan doesn't track
has_content; both setext/thematic guards are unconditionally enabled.at_paragraph_break(p, true)at line 1235 hardcodeshas_content = true. The parse path (handle_inline_newline) gates the setext/thematic break on the actualhas_contentflag accumulated during parse. The re-check added at lines 1273–1278 (post-list-indent stripping) has the same gap — its parse-path mirror at lines 965–969 is guarded byif is_setext && has_content.In practice
inline_list_source_lenis never called when the inline list starts with a NEWLINE (paragraphs can't start with one), so the risk is limited to emphasis-context sizing in edge cases. But this is a direct parity gap contrary to the PR's stated goal of aligning decision points.A
has_contentlocal flag (mirroring howparse_inline_item_listtracks it) would close the gap:💡 Sketch — add `has_content` tracking to the prescan
fn inline_list_source_len(p: &mut MarkdownParser) -> usize { p.lookahead(|p| { let mut len = 0usize; + let mut has_content = false; loop { // … if p.at(NEWLINE) { // … - if at_paragraph_break(p, true) { + if at_paragraph_break(p, has_content) { break; } // … // After stripping list indent, re-check setext/thematic markers - if p.at(MD_SETEXT_UNDERLINE_LITERAL) - || (p.at(MD_THEMATIC_BREAK_LITERAL) - && is_dash_only_thematic_break_text(p.cur_text())) - { - break; - } + if has_content + && (p.at(MD_SETEXT_UNDERLINE_LITERAL) + || (p.at(MD_THEMATIC_BREAK_LITERAL) && is_dash_only_thematic_break(p))) + { + break; + } continue; } // … len += p.cur_text().len(); p.bump(p.cur()); + // mirror has_content tracking from parse_inline_item_list + let inline_end: usize = p.cur_range().start().into(); + // (simplified: any non-NEWLINE token counts as content for prescan purposes) + has_content = true; } len }) }Also applies to: 1273-1278
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this relevant @jfmcdowell ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this issue was real and is fixed in #9313: the prescan mismatch in
inline_list_source_lenis now gated withhas_contentfor setext/thematic checks (aligned withparse_inline_item_list). Revalidated with parser tests and CommonMark conformance passing. It slipped past the keeper.