Fix grid table open last cell taking a | from the next line (#494)

To find a closing `|` at the end of the last column, GridTableParser used
PeekCharExtra, which ignores the end of the slice. When the line was
shorter than the table, it could read the next line instead, and a `|`
there made the cell run past the end of the line, so the next line's
leading `|` ended up in the cell. Use PeekChar, which stays within the
current line.
This commit is contained in:
dualfroz committed 2026-10-03 02:46:01 +02:00
1 parent 1d93169fc0
commit 2b9fbfb252
2 files changed
+26 -1

No files matched your search

+25
View File
@@ -346,6 +346,31 @@ $$
TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseGridTables().Build());
}
[Test]
public void TestGridTableLastCellWithoutClosingPipe()
{
// The last cell is open and shorter than the column, and the next line has
// a `|` where this one would end: https://github.com/xoofx/markdig/issues/494
var input = @"
+-----+----------+
| 6 | 1
| |
+-----+----------+";
var expected = @"<table>
<col style=""width:33.33%"" />
<col style=""width:66.67%"" />
<tbody>
<tr>
<td>6</td>
<td>1</td>
</tr>
</tbody>
</table>
";
TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseGridTables().Build());
}
[Test]
public void TestDefinitionListInListItemWithBlankLine()
{
@@ -279,7 +279,7 @@ public class GridTableParser : BlockParser
else
{
var columnEnd = columns[columns.Count - 1].End;
var columnEndChar = line.PeekCharExtra(columnEnd);
var columnEndChar = line.PeekChar(columnEnd);
// If there is a `|` (or a `+` in the case that we are dealing with a row line
// with spanned contents) exactly at the expected end of the table row, we cut the line
// otherwise we allow to have the last cell of a row to be open for longer cell content