Skip to content

Commit c436465

Browse files
authored
Merge pull request #885 from dannyp32/supportTableWithoutExtraLine
Add support for a table without an extra new line before it
2 parents 7ff8db9 + d548b82 commit c436465

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Markdig.Tests/TestPipeTable.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public sealed class TestPipeTable
1010
[TestCase("| S | T |\r\n|---|---|\t\r\n| G | H |")]
1111
[TestCase("| S | T |\r\n|---|---|\f\r\n| G | H |")]
1212
[TestCase("| S | \r\n|---|\r\n| G |\r\n\r\n| D | D |\r\n| ---| ---| \r\n| V | V |", 2)]
13+
[TestCase("a\r| S | T |\r|---|---|")]
14+
[TestCase("a\n| S | T |\r|---|---|")]
1315
public void TestTableBug(string markdown, int tableCount = 1)
1416
{
1517
MarkdownDocument document =

src/Markdig/Extensions/Tables/PipeTableParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
4848
}
4949

5050
var c = slice.CurrentChar;
51+
var isNewLineFollowedByPipe = (c == '\n' || c == '\r') && slice.PeekChar() == '|';
5152

5253
// If we have not a delimiter on the first line of a paragraph, don't bother to continue
5354
// tracking other delimiters on following lines
@@ -60,18 +61,17 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
6061

6162
if (tableState is null)
6263
{
63-
6464
// A table could be preceded by an empty line or a line containing an inline
6565
// that has not been added to the stack, so we consider this as a valid
6666
// start for a table. Typically, with this, we can have an attributes {...}
6767
// starting on the first line of a pipe table, even if the first line
6868
// doesn't have a pipe
69-
if (processor.Inline != null && (localLineIndex > 0 || c == '\n' || c == '\r'))
69+
if (processor.Inline != null && (localLineIndex > 0 || c == '\n' || c == '\r') && !isNewLineFollowedByPipe)
7070
{
7171
return false;
7272
}
7373

74-
if (processor.Inline is null)
74+
if (processor.Inline is null || isNewLineFollowedByPipe)
7575
{
7676
isFirstLineEmpty = true;
7777
}

0 commit comments

Comments
 (0)