Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,140 @@ public void interruptsParagraph() {
""");
}

@Test
public void bulletListWithPipeEndsTable() {
assertRendering(
"""
| Header |
| --- |
* | [Keep me](https://example.com/) |
""",
"""
<table>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
</table>
<ul>
<li>| <a href="https://example.com/">Keep me</a> |</li>
</ul>
""");
}

@Test
public void bodyRowThenBulletListWithPipeEndsTable() {
assertRendering(
"""
| Header |
| --- |
| a |
- | b |
""",
"""
<table>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
</tr>
</tbody>
</table>
<ul>
<li>| b |</li>
</ul>
""");
}

@Test
public void otherBlockStartsEndTable() {
// Each of these lines contains a pipe but starts another block, which ends the table.
assertRendering(
"""
| Header |
| --- |
> | quote |
""",
"""
<table>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
</table>
<blockquote>
<p>| quote |</p>
</blockquote>
""");
assertRendering(
"""
| Header |
| --- |
# heading | x
""",
"""
<table>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
</table>
<h1>heading | x</h1>
""");
assertRendering(
"""
| Header |
| --- |
```a|b
code
```
""",
"""
<table>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
</table>
<pre><code class="language-a|b">code
</code></pre>
""");
}

@Test
public void indentedLineWithPipeStaysTableRow() {
// An indented code block can not interrupt a table, just like it can not interrupt a
// paragraph.
assertRendering(
"""
| Header |
| --- |
| a |
""",
"""
<table>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
</tr>
</tbody>
</table>
""");
}

@Test
public void attributeProviderIsApplied() {
AttributeProviderFactory factory =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading