fix: parse empty list item with trailing space#3984
Conversation
A bare list marker followed only by a space (e.g. `- ` or `1. `) was not recognized as a list and fell through to a paragraph, so `- ` rendered as `<p>- </p>` instead of an empty list item. A marker with no trailing space (`-`, `1.`) and an empty item that continues an existing list were already handled correctly, making the behavior inconsistent. The block `list` rule required content after the marker's whitespace (`[ \t][^\n]+?`), so a marker followed only by whitespace failed to match. Relax it to `[ \t][^\n]*?` so a marker with trailing whitespace and no content still starts a list, matching the CommonMark reference and markdown-it. To keep CommonMark's rule that an empty list item cannot interrupt a paragraph, the paragraph list-interrupt patterns now require a non-blank character after the marker, so `foo\n+ ` stays a single paragraph while `foo\n- bar` still interrupts.
|
@sarathfrancis90 is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Code Review
This pull request updates markdown parsing rules in src/rules.ts to ensure that only non-empty lists starting with 1 can interrupt a paragraph, and updates the list regex to match zero or more non-newline characters. It also adds new test specs for list items with empty trailing spaces. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thanks for the quick review, @UziTech! 🙏 Glad it lines up with the CommonMark reference and markdown-it behavior — happy to adjust anything if needed. |
Marked version: 18.0.4 (master)
Markdown flavor: CommonMark
Description
A bare list marker followed only by a space (e.g.
-,*,1.,1)) was not recognized as a list. It fell through to the paragraph rule and rendered as a paragraph instead of an empty list item.This is internally inconsistent: a marker with no trailing space already worked, and an empty item that continues an existing list also worked — only a marker followed by a single trailing space was broken.
Expectation
-(and*,1.,1)) should produce an empty list item, matching the CommonMark reference implementation (commonmark 0.31.2) and markdown-it 14.2.0 in CommonMark mode:Result
marked produced a paragraph containing the literal marker:
Root cause
The block
listrule required at least one content character after the marker's whitespace:The
+?means a marker followed only by whitespace cannot match, so it falls through to the paragraph rule. A previous change (PR #3890) updated the marker prefix but left this content group as+?, so the trailing-space case stayed broken (the fixture there had no trailing space). This PR is the complementary fix.Fix
Relax the content group from
[ \t][^\n]+?to[ \t][^\n]*?so a marker followed only by whitespace still starts a list:To preserve CommonMark's rule that an empty list item cannot interrupt a paragraph, the paragraph (and GFM block) list-interrupt patterns now require a non-blank character after the marker, so
foo\n+stays a single paragraph whilefoo\n- barstill interrupts. The GFM table interrupt pattern is intentionally left unchanged, since a bare bullet still ends table rows.Test evidence
test/specs/new/list_item_empty_trailing_space.{md,html}covering-,*,1.,1), the paragraph non-interrupt casefoo\n+, and the still-interrupting casebar\n1..test:specs1743 pass / 0 fail,test:unit188 pass / 0 fail, plustest:cjs,test:umd,test:types(attw) andtest:lint. CommonMark "List items" (48/48) and "Lists" (26/26) remain at 100% with no regression.Contributor
Committer
In most cases, this should be a different person than the contributor.