Skip to content

fix: end a list item before a lazy line after an empty or non-paragraph nested block - #4183

Open
lprnmns wants to merge 1 commit into
markedjs:masterfrom
lprnmns:fix/lazy-line-after-nested-block
Open

lprnmns wants to merge 1 commit into
markedjs:masterfrom
lprnmns:fix/lazy-line-after-nested-block

Conversation

@lprnmns

@lprnmns lprnmns commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Marked version: 18.1.2 (master)

Markdown flavor: CommonMark|GitHub Flavored Markdown

Description

A line that is not indented enough only stays in a list item when it is paragraph continuation text (CommonMark 5.2). Tokenizer.list decides this by looking at the previous line, but when that line is the item's first line it can itself open a nested list item or block quote. The checks then see - or > instead of the block inside, so the lazy line is pulled into the outer item even when the nested block is empty or is a heading, fence, thematic break or indented code.

This change looks past nested list and block quote markers on the item's first line before running the existing checks, and ends the item when nothing is left (an empty nested item or block quote). It only does this for the first line, which always starts a block, and not for lines with tabs, whose width depends on their column. This is the list counterpart of #4178, which handles > -\nfoo.

Expectation

- -\nnot in the list gives <ul><li><ul><li></li></ul></li></ul><p>not in the list</p>, matching commonmark.js.

Result

<ul><li><ul><li></li></ul><p>not in the list</p></li></ul>. The same happens with 1. - , - 1., - > , - - # heading, - - ```, - - *** and - - code followed by an unindented line. - - item\nfoo still continues the nested paragraph.

What was attempted

The new test/specs/new/list_lazy_after_nested_block spec fails without the change and passes with it; its expected HTML matches commonmark.js. npm test passes. I also compared old and new output against commonmark.js on 600,000 random inputs built from list markers, block quote markers, indentation and block starts: no input that matched before differs now.

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

@vercel

vercel Bot commented Nov 2, 2026

Copy link
Copy Markdown

@lprnmns is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
marked-website Ready Ready Preview Nov 9, 2026 11:01pm UTC

Request Review

@UziTech UziTech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 💯

@yxshee yxshee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer merges with master, but only because of the fixture name: #4179 added test/specs/new/list_lazy_after_nested_block.md/.html, the same names this PR uses. The Tokenizer.ts and rules.ts changes merge cleanly; with this PR's fixture renamed, master plus this branch passes all spec tests, and the renamed fixture still fails on master without the change. So renaming the fixture should be all the rebase needs.

@lprnmns
lprnmns force-pushed the fix/lazy-line-after-nested-block branch from 0d79e61 to 5f0f603 Compare November 9, 2026 10:36
@lprnmns

lprnmns commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto master and renamed the fixture to list_lazy_after_empty_or_non_paragraph_block, since #4179 added a fixture with the same name. All 1991 spec tests pass, and the renamed fixture still fails without the change.

This branch was successfully deployed

1 active deployment
Preview — 5f0f6038 Deployed Nov 9, 2026 by vercel[bot]
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.

3 participants