mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-04 05:44:50 +00:00
Fix for table depth error when cell contains backticks (#891)
* failing test * fixed bug with table containing back tick which causes depth error
This commit is contained in:
@@ -57,4 +57,48 @@ public sealed class TestPipeTable
|
||||
Assert.AreEqual(0, column.Width);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TableWithUnbalancedCodeSpanParsesWithoutDepthLimitError()
|
||||
{
|
||||
const string markdown = """
|
||||
| Count | A | B | C | D | E |
|
||||
|-------|---|---|---|---|---|
|
||||
| 0 | B | C | D | E | F |
|
||||
| 1 | B | `C | D | E | F |
|
||||
| 2 | B | `C | D | E | F |
|
||||
| 3 | B | C | D | E | F |
|
||||
| 4 | B | C | D | E | F |
|
||||
| 5 | B | C | D | E | F |
|
||||
| 6 | B | C | D | E | F |
|
||||
| 7 | B | C | D | E | F |
|
||||
| 8 | B | C | D | E | F |
|
||||
| 9 | B | C | D | E | F |
|
||||
| 10 | B | C | D | E | F |
|
||||
| 11 | B | C | D | E | F |
|
||||
| 12 | B | C | D | E | F |
|
||||
| 13 | B | C | D | E | F |
|
||||
| 14 | B | C | D | E | F |
|
||||
| 15 | B | C | D | E | F |
|
||||
| 16 | B | C | D | E | F |
|
||||
| 17 | B | C | D | E | F |
|
||||
| 18 | B | C | D | E | F |
|
||||
| 19 | B | C | D | E | F |
|
||||
""";
|
||||
|
||||
var pipeline = new MarkdownPipelineBuilder()
|
||||
.UseAdvancedExtensions()
|
||||
.Build();
|
||||
|
||||
MarkdownDocument document = null!;
|
||||
Assert.DoesNotThrow(() => document = Markdown.Parse(markdown, pipeline));
|
||||
|
||||
var tables = document.Descendants().OfType<Table>().ToArray();
|
||||
Assert.That(tables, Has.Length.EqualTo(1));
|
||||
|
||||
string html = string.Empty;
|
||||
Assert.DoesNotThrow(() => html = Markdown.ToHtml(markdown, pipeline));
|
||||
Assert.That(html, Does.Contain("<table"));
|
||||
Assert.That(html, Does.Contain("<td>`C</td>"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +196,16 @@ public class PipeTableParser : InlineParser, IPostInlineProcessor
|
||||
// Continue
|
||||
if (tableState is null || container is null || tableState.IsInvalidTable || !tableState.LineHasPipe ) //|| tableState.LineIndex != state.LocalLineIndex)
|
||||
{
|
||||
if (tableState is not null)
|
||||
{
|
||||
foreach (var inline in tableState.ColumnAndLineDelimiters)
|
||||
{
|
||||
if (inline is PipeTableDelimiterInline pipeDelimiter)
|
||||
{
|
||||
pipeDelimiter.ReplaceByLiteral();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public class CodeInlineParser : InlineParser
|
||||
Debug.Assert(match is not ('\r' or '\n'));
|
||||
|
||||
// Match the opened sticks
|
||||
int openingStart = slice.Start;
|
||||
int openSticks = slice.CountAndSkipChar(match);
|
||||
|
||||
// A backtick string is a string of one or more backtick characters (`) that is neither preceded nor followed by a backtick.
|
||||
@@ -75,8 +76,25 @@ public class CodeInlineParser : InlineParser
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (closeSticks == 0)
|
||||
|
||||
if (closeSticks == 0)
|
||||
{
|
||||
ReadOnlySpan<char> lookAhead = span.Length > 1 ? span.Slice(1) : ReadOnlySpan<char>.Empty;
|
||||
while (!lookAhead.IsEmpty && (lookAhead[0] == '\r' || lookAhead[0] == '\n'))
|
||||
{
|
||||
lookAhead = lookAhead.Slice(1);
|
||||
}
|
||||
int whitespace = 0;
|
||||
while (whitespace < lookAhead.Length && (lookAhead[whitespace] == ' ' || lookAhead[whitespace] == '\t'))
|
||||
{
|
||||
whitespace++;
|
||||
}
|
||||
if (whitespace < lookAhead.Length && lookAhead[whitespace] == '|')
|
||||
{
|
||||
slice.Start = openingStart;
|
||||
return false;
|
||||
}
|
||||
|
||||
containsNewLines = true;
|
||||
span = span.Slice(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user