Skip to content

Keep list tight for a blank line inside an open fenced code block - #481

Open
bardrop wants to merge 1 commit into
commonmark:mainfrom
bardrop-oss:fix-loose-list-fenced-code
Open

bardrop wants to merge 1 commit into
commonmark:mainfrom
bardrop-oss:fix-loose-list-fenced-code

Conversation

@bardrop

@bardrop bardrop commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

In this input the blank line is inside the fenced code block. The fence is never closed, so the code block runs until the next list item starts:

- a
- ```

- b

commonmark-java made the list loose:

<ul>
<li>
<p>a</p>
</li>
<li>
<pre><code>
</code></pre>
</li>
<li>
<p>b</p>
</li>
</ul>

But the blank line is part of the code block (it shows up in the <code> content), so it does not separate the items. cmark and commonmark.js keep the list tight (<li>a</li>, <li>b</li>). Same thing for a blank line in a fenced code block of a nested list, when more content of the outer item follows:

- - ```

  b

Here the outer list should stay tight (b</li>), but it got <p>b</p>.

The fix: on the line after a blank line, if a fenced code block is still the active block, the blank line was part of that code block, so ListBlockParser and ListItemParser don't count it. A blank line that ends a block quote around the fence still counts, so - > ~~~, blank line, - b stays loose, like cmark and commonmark.js.

I left HTML blocks alone on purpose: for - <!--, blank line, - b, cmark says loose and commonmark.js says tight.

Tests: added 3 cases to ListTightLooseTest. Before the fix, 2 of them fail (19 run, 2 failures). After the fix all 19 pass. Full mvn test passes (2305 in commonmark, all other modules green), and mvn spotless:check passes. Expected outputs are what cmark-gfm and commonmark.js 0.31.2 produce.

In this input the blank line is part of the fenced code block, which is
only closed by the next list item:

- a
- ```

- b

The blank line did not separate the items, but the list was made loose.
Same for a blank line in a fenced code block of a nested list followed by
more content of the outer item. cmark and commonmark.js keep these lists
tight. A blank line in a fenced code block that is still open on the next
line was part of the code block, so don't count it.

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