Repository navigation
Conversation
…ns a pipe A table row was continued for any line containing a pipe, so a line that starts another block (list item, block quote, heading, fenced code, HTML) was parsed as a row. Try block starts after a block that can have lazy continuation lines, as for a paragraph, and keep indented code from interrupting it.
| // adding children to the last matched container: | ||
| boolean tryBlockStarts = | ||
| blockParser.getBlock() instanceof Paragraph || blockParser.isContainer(); | ||
| blockParser.getBlock() instanceof Paragraph |
There was a problem hiding this comment.
WDYT about removing the instanceof Paragraph (given ParagraphParser returns true for canHaveLazyContinuationLines)?
Theoretically someone could have implemented a block parser with a Paragraph block but with canHaveLazyContinuationLines returning false, which would mean we'd change behavior, but it seems unlikely.
There was a problem hiding this comment.
Good call, removed. ParagraphParser already returns true for canHaveLazyContinuationLines, so the instanceof Paragraph branch added nothing for the built-in parsers, and I agree a custom parser with a Paragraph block and no lazy continuation is unlikely. Full ./mvnw test passes after the change (the table tests, including the indented-row case, still included).
Why
With the tables extension, a line that contains a pipe and starts another block is parsed as a table row. The case from #482:
renders one table whose body is
<tr><td>*</td></tr>, and the link is lost. cmark-gfm renders the table and then a list. The GFM spec says the table ends at the first empty line or the beginning of another block-level structure.The cause is not specific to bullets.
DocumentParseronly tries block starts after a paragraph or a container, andTableBlockParser.tryContinueaccepts any line with a pipe, so a block quote (> | x |), a heading (# h | x), a fenced code block (```a|b), an HTML block and an ordered list item were swallowed the same way (checked before the change).Fixes #482.
What changes
DocumentParser: also try block starts when the matched block parsercanHaveLazyContinuationLines(). OnlyParagraphParser(already covered) andTableBlockParserreturn true, so in practice this adds tables.IndentedCodeBlockParser: an indented code block can not interrupt a block that takes lazy continuation lines, as it can not interrupt a paragraph. Without this, an existing test (paddingWithCodeBlockIndentation, a row indented by four spaces) fails.TablesTest: bullet with a pipe after the header and after a body row, block quote / heading / fenced code, and an indented row that stays a table row.CHANGELOG.md: entry under[Unreleased].Tests
./mvnw -B teston the whole repository: BUILD SUCCESS, no failure (2322 tests counted across modules, including the CommonMark and GFM spec tests).commonmark/srcrestored tomain:./mvnw -B -pl commonmark-ext-gfm-tables -am test -Dtest=TablesTest: 3 of the new tests fail (bulletListWithPipeEndsTable,bodyRowThenBulletListWithPipeEndsTable,otherBlockStartsEndTable);indentedLineWithPipeStaysTableRowis a guard for the second change and passes on both../mvnw spotless:checkoncommonmark-ext-gfm-tables: clean. Oncommonmarkit reports one violation inBackslashInlineParser.java, a file this PR does not touch; it is the same onmainwith JDK 21.>,#, a fence or an HTML tag now ends the table, as in cmark-gfm. A row that starts with a list marker (- | a |) used to be a one-cell row.