Skip to content

Make list loose for blank line after HTML block or indented code - #463

Open
ybai08 wants to merge 1 commit into
commonmark:mainfrom
ybai08:fix-loose-list-blank-line-after-html-block
Open

ybai08 wants to merge 1 commit into
commonmark:mainfrom
ybai08:fix-loose-list-blank-line-after-html-block

Conversation

@ybai08

@ybai08 ybai08 commented Oct 18, 2026

Copy link
Copy Markdown

A blank line between two blocks of a list item should make the list loose, but ListItemParser only counted the blank line if the active block was a paragraph or a list item. So these rendered as tight lists (no <p> around bar):

- <!-- comment -->

  bar
-     foo

  bar
- foo
  -

  bar

The other way around, a blank line between two blocks of a nested item also made the outer list loose if the outer item got another block later:

- a
  - b

    c
  # d

Here the outer list should stay tight (<li>a).

The fix checks whether the line before a new block in the item was blank instead of looking at the active block. That matches commonmark.js and cmark, which check for a gap between consecutive children (endsWithBlankLine), and blank lines inside a code block that continues afterwards still don't count.

Tests added in ListTightLooseTest: the four cases above fail without the change, and tightListWithIndentedCodeBlock guards the blank-line-inside-code case. Expected output is what cmark 0.31.2 and commonmark.js 0.31.2 produce. mvn test (all modules) and mvn spotless:check pass.

A blank line between two blocks of a list item makes the list loose. The
blank line was only taken into account if it came after a paragraph or
nested list item, so it was missed after an HTML block, an indented code
block or a setext heading. And a blank line between two blocks of a
nested item also made the outer list loose if the outer item got another
block later.

Instead, check whether the line before a new block in the item was blank,
like commonmark.js and cmark do.

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.

1 participant