diff --git a/CHANGELOG.md b/CHANGELOG.md
index f94d6c01..e2bb6a86 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html),
with the exception that 0.x versions can break between minor versions.
+## [Unreleased]
+### Fixed
+- GFM tables: a line that starts another block (a list item, block quote, heading,
+ fenced code block, HTML block) now ends the table, also when it contains a pipe.
+ Before, such a line was parsed as a table row. An indented code block still can not
+ interrupt a table, like it can not interrupt a paragraph.
+
## [0.33.0] - 2026-11-20
### Added
- New artifact `org.commonmark:commonmark-ext-github` with a `GitHubExtensions`
@@ -636,6 +643,7 @@ API breaking changes (caused by changes in spec):
Initial release of commonmark-java, a port of commonmark.js with extensions
for autolinking URLs, GitHub flavored strikethrough and tables.
+[Unreleased]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.33.0...HEAD
[0.33.0]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.32.0...commonmark-parent-0.33.0
[0.32.0]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.31.0...commonmark-parent-0.32.0
[0.31.0]: https://github.com/commonmark/commonmark-java/compare/commonmark-parent-0.30.1...commonmark-parent-0.31.0
diff --git a/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java b/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java
index 31df43b7..150bc7d5 100644
--- a/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java
+++ b/commonmark-ext-gfm-tables/src/test/java/org/commonmark/ext/gfm/tables/TablesTest.java
@@ -1150,6 +1150,140 @@ public void interruptsParagraph() {
""");
}
+ @Test
+ public void bulletListWithPipeEndsTable() {
+ assertRendering(
+ """
+ | Header |
+ | --- |
+ * | [Keep me](https://example.com/) |
+ """,
+ """
+
+
+ """);
+ }
+
+ @Test
+ public void bodyRowThenBulletListWithPipeEndsTable() {
+ assertRendering(
+ """
+ | Header |
+ | --- |
+ | a |
+ - | b |
+ """,
+ """
+
+
+
+ | Header |
+
+
+
+
+ | a |
+
+
+
+
+ """);
+ }
+
+ @Test
+ public void otherBlockStartsEndTable() {
+ // Each of these lines contains a pipe but starts another block, which ends the table.
+ assertRendering(
+ """
+ | Header |
+ | --- |
+ > | quote |
+ """,
+ """
+
+
+ | quote |
+
+ """);
+ assertRendering(
+ """
+ | Header |
+ | --- |
+ # heading | x
+ """,
+ """
+
+ heading | x
+ """);
+ assertRendering(
+ """
+ | Header |
+ | --- |
+ ```a|b
+ code
+ ```
+ """,
+ """
+
+ code
+
+ """);
+ }
+
+ @Test
+ public void indentedLineWithPipeStaysTableRow() {
+ // An indented code block can not interrupt a table, just like it can not interrupt a
+ // paragraph.
+ assertRendering(
+ """
+ | Header |
+ | --- |
+ | a |
+ """,
+ """
+
+
+
+ | Header |
+
+
+
+
+ | a |
+
+
+
+ """);
+ }
+
@Test
public void attributeProviderIsApplied() {
AttributeProviderFactory factory =
diff --git a/commonmark/src/main/java/org/commonmark/internal/DocumentParser.java b/commonmark/src/main/java/org/commonmark/internal/DocumentParser.java
index 3724a8cf..36cb8e14 100644
--- a/commonmark/src/main/java/org/commonmark/internal/DocumentParser.java
+++ b/commonmark/src/main/java/org/commonmark/internal/DocumentParser.java
@@ -249,7 +249,7 @@ private void parseLine(String ln, int inputIndex) {
// Unless last matched container is a code block, try new container starts,
// adding children to the last matched container:
boolean tryBlockStarts =
- blockParser.getBlock() instanceof Paragraph || blockParser.isContainer();
+ blockParser.isContainer() || blockParser.canHaveLazyContinuationLines();
while (tryBlockStarts) {
lastIndex = index;
findNextNonSpace();
diff --git a/commonmark/src/main/java/org/commonmark/internal/IndentedCodeBlockParser.java b/commonmark/src/main/java/org/commonmark/internal/IndentedCodeBlockParser.java
index b05b0a45..6c444a96 100644
--- a/commonmark/src/main/java/org/commonmark/internal/IndentedCodeBlockParser.java
+++ b/commonmark/src/main/java/org/commonmark/internal/IndentedCodeBlockParser.java
@@ -60,10 +60,12 @@ public static class Factory extends AbstractBlockParserFactory {
@Override
public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) {
- // An indented code block cannot interrupt a paragraph.
+ // An indented code block cannot interrupt a paragraph (or any other block that takes
+ // lazy continuation lines, like a table).
if (state.getIndent() >= Parsing.CODE_BLOCK_INDENT
&& !state.isBlank()
- && !(state.getActiveBlockParser().getBlock() instanceof Paragraph)) {
+ && !(state.getActiveBlockParser().getBlock() instanceof Paragraph)
+ && !state.getActiveBlockParser().canHaveLazyContinuationLines()) {
return BlockStart.of(new IndentedCodeBlockParser())
.atColumn(state.getColumn() + Parsing.CODE_BLOCK_INDENT);
} else {