Add support for a table without an extra new line before it

This commit is contained in:
Daniel Pino
2025-08-09 08:50:49 +00:00
parent 7ff8db9016
commit d548b82bcd
2 changed files with 5 additions and 3 deletions

View File

@@ -10,6 +10,8 @@ public sealed class TestPipeTable
[TestCase("| S | T |\r\n|---|---|\t\r\n| G | H |")]
[TestCase("| S | T |\r\n|---|---|\f\r\n| G | H |")]
[TestCase("| S | \r\n|---|\r\n| G |\r\n\r\n| D | D |\r\n| ---| ---| \r\n| V | V |", 2)]
[TestCase("a\r| S | T |\r|---|---|")]
[TestCase("a\n| S | T |\r|---|---|")]
public void TestTableBug(string markdown, int tableCount = 1)
{
MarkdownDocument document =

View File

@@ -48,6 +48,7 @@ public class PipeTableParser : InlineParser, IPostInlineProcessor
}
var c = slice.CurrentChar;
var isNewLineFollowedByPipe = (c == '\n' || c == '\r') && slice.PeekChar() == '|';
// If we have not a delimiter on the first line of a paragraph, don't bother to continue
// tracking other delimiters on following lines
@@ -60,18 +61,17 @@ public class PipeTableParser : InlineParser, IPostInlineProcessor
if (tableState is null)
{
// A table could be preceded by an empty line or a line containing an inline
// that has not been added to the stack, so we consider this as a valid
// start for a table. Typically, with this, we can have an attributes {...}
// starting on the first line of a pipe table, even if the first line
// doesn't have a pipe
if (processor.Inline != null && (localLineIndex > 0 || c == '\n' || c == '\r'))
if (processor.Inline != null && (localLineIndex > 0 || c == '\n' || c == '\r') && !isNewLineFollowedByPipe)
{
return false;
}
if (processor.Inline is null)
if (processor.Inline is null || isNewLineFollowedByPipe)
{
isFirstLineEmpty = true;
}