Skip to content

fix: text after a heading or code block in a nested list item is pulled into the outer item - #4179

Merged
UziTech merged 1 commit into
markedjs:masterfrom
yxshee:fix/list-lazy-after-nested-block
Nov 8, 2026
Merged

UziTech merged 1 commit into
markedjs:masterfrom
yxshee:fix/list-lazy-after-nested-block

Conversation

@yxshee

@yxshee yxshee commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Marked version: 18.1.2 (also master at 8babc79)

Markdown flavor: CommonMark

Description

A line with less indentation than a list item is only a lazy continuation when it continues a paragraph. When the line before it ends a fenced code block, or is a heading or a thematic break inside a nested list item or block quote, there is no open paragraph, so the list should end there. marked keeps the line in the outer list item instead.

Expectation

- Setup
  - Install it:
    ```
    npm install
    ```
Then run it.

Then run it. is a paragraph after the list (commonmark.js 0.31 and the CommonMark dingus agree).

Result

marked 18.1.2 renders <p>Then run it.</p> inside the outer <li>. The same happens for - - # heading and - > *** followed by an unindented line; with - > *** the text even ends up as bare text in the item.

Cause

In the "not enough indentation" branch of the list tokenizer, line is the previous line already relative to the item content, but it was tested with fencesBeginRegex(indent), headingBeginRegex(indent) and hrRegex(indent), which only allow indent - 1 leading spaces. A closing fence in a nested item (three backticks after two spaces, relative to the outer item) has more than that. Those checks also never looked past a nested list marker or > on the line.

The fix tests the previous line with the block rules (0 to 3 spaces), after stripping nested list and block quote markers, and only when that line was not itself a lazy line (a lazy line is paragraph text, so - a\nb\n# c behaves as before). Pedantic mode is unchanged.

Contributor

  • Test(s) exist to ensure functionality and minimize regression: test/specs/new/list_lazy_after_nested_block.md covers the fence, heading, hr and block quote cases, plus a nested lazy line that must stay in the nested item.
  • 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.

A line with less indentation than a list item is only a lazy
continuation when it continues a paragraph. The list tokenizer checked
the previous line for a fence, heading or hr, but it used the regexes
scaled to the item indent on a line that is already relative to the
item content, and it did not look inside a nested list item or
blockquote on that line. So text after `- - # heading`, `- > ***`, or a
fenced code block in a nested item was pulled into the outer item.
@vercel

vercel Bot commented Nov 2, 2026

Copy link
Copy Markdown

@yxshee 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 2, 2026 2:39pm 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! ๐Ÿ’ฏ

@UziTech
UziTech merged commit 4cb767a into markedjs:master Nov 8, 2026
8 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 9, 2026
# [18.2.0](v18.1.3...v18.2.0) (2026-11-09)

### Bug Fixes

* keep hard line breaks in image alt text ([#4187](#4187)) ([ed54c54](ed54c54))
* let emphasis open after the other delimiter character ([#4169](#4169)) ([219492a](219492a))
* let emphasis open and close in angle brackets that are not html ([#4190](#4190)) ([7bfa1f7](7bfa1f7))
* preserve zero from named extension renderers ([#4199](#4199)) ([b81a00a](b81a00a))
* text after a heading or code block in a nested list item is pulled into the outer item ([#4179](#4179)) ([4cb767a](4cb767a))

### Features

* add lastToken to lexer state ([#4160](#4160)) ([e4ab77f](e4ab77f))

This branch was successfully deployed

1 active deployment
Preview โ€” 495edd14 Deployed Nov 2, 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