Skip to content

Don't let lists interrupt a paragraph with only link reference definitions - #472

Open
ybai08 wants to merge 1 commit into
commonmark:mainfrom
ybai08:fix-list-interrupt-definition-paragraph
Open

ybai08 wants to merge 1 commit into
commonmark:mainfrom
ybai08:fix-list-interrupt-definition-paragraph

Conversation

@ybai08

@ybai08 ybai08 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

An ordered list that doesn't start with 1, or an empty list item, can't interrupt a paragraph (spec section 5.2). This wasn't applied when the paragraph so far only had link reference definitions:

[foo]: /url
2. a

rendered as <ol start="2"><li>a</li></ol> instead of <p>2. a</p>. The same happened for an empty item ([foo]: /url then -), after a definition with a title, and inside a block quote.

ListBlockParser.Factory decided whether it was in a paragraph with !matchedBlockParser.getParagraphLines().isEmpty(). getParagraphLines() leaves out the lines already parsed as definitions, so for a paragraph with only definitions it was empty, and the list was allowed to interrupt it. But that paragraph is still open, and the next line is paragraph continuation text, as spec example 217 shows for === after a definition (it stays in the paragraph instead of becoming a setext heading). The check now looks at whether the matched block is a Paragraph, as HtmlBlockParser already does for type 7.

commonmark.js 0.31.2 renders all the new test cases the same way.

SpecialInputTest#listCanNotInterruptParagraphWithOnlyLinkReferenceDefinitions fails without the change. mvn install (all modules) and mvn spotless:check (JDK 17) pass.

For context, this came up when comparing the HTML output of commonmark-java with commonmark.js 0.31.2 on 150,000 generated inputs. With the change, the two inputs whose output changed now match commonmark.js, and no other output changed.

…tions

A paragraph whose lines so far are all link reference definitions is
still an open paragraph, so an ordered list not starting with 1 or an
empty list item can't interrupt it. ListBlockParser checked for
remaining paragraph lines instead, so e.g. "[foo]: /url\n2. a" was
rendered as a list starting at 2 instead of a paragraph "2. a".

Check whether the matched block is a paragraph, like HtmlBlockParser
does for type 7. This matches commonmark.js 0.31.2.

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