fix broken newline parsing for LineBreakInline and PipeTableParser

This commit is contained in:
Ruud Poutsma
2020-11-06 13:27:46 +01:00
parent 35b64052d6
commit 8e8b95c3bb
3 changed files with 12 additions and 17 deletions

View File

@@ -1,12 +0,0 @@
using Markdig.Renderers.Normalize;
using Markdig.Syntax;
using NUnit.Framework;
using System.IO;
namespace Markdig.Tests.RoundtripSpecs
{
internal static class TestHelper
{
}
}

View File

@@ -31,7 +31,7 @@ namespace Markdig.Extensions.Tables
public PipeTableParser(LineBreakInlineParser lineBreakParser, PipeTableOptions options = null)
{
this.lineBreakParser = lineBreakParser ?? throw new ArgumentNullException(nameof(lineBreakParser));
OpeningCharacters = new[] { '|', '\n' };
OpeningCharacters = new[] { '|', '\n', '\r' };
Options = options ?? new PipeTableOptions();
}
@@ -67,7 +67,7 @@ namespace Markdig.Extensions.Tables
// 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'))
if (processor.Inline != null && (localLineIndex > 0 || c == '\n' || c == '\r'))
{
return false;
}
@@ -81,7 +81,7 @@ namespace Markdig.Extensions.Tables
processor.ParserStates[Index] = tableState;
}
if (c == '\n')
if (c == '\n' || c == '\r')
{
if (!isFirstLineEmpty && !tableState.LineHasPipe)
{

View File

@@ -19,7 +19,7 @@ namespace Markdig.Parsers.Inlines
/// </summary>
public LineBreakInlineParser()
{
OpeningCharacters = new[] {'\n', '\r'}; // TODO: RTP: this causes LineBreakInline to be parsed for non-trivia parser
OpeningCharacters = new[] { '\n', '\r' }; // TODO: RTP: this causes LineBreakInline to be parsed for non-trivia parser
}
/// <summary>
@@ -57,6 +57,13 @@ namespace Markdig.Parsers.Inlines
newline = Newline.LineFeed;
}
}
else
{
if (slice.CurrentChar == '\r' && slice.PeekChar() == '\n')
{
slice.NextChar(); // Skip \n
}
}
slice.NextChar(); // Skip \r or \n
processor.Inline = new LineBreakInline
@@ -67,7 +74,7 @@ namespace Markdig.Parsers.Inlines
Column = column,
Newline = newline
};
processor.Inline.Span.End = processor.Inline.Span.Start;
processor.Inline.Span.End = processor.Inline.Span.Start + (newline == Newline.CarriageReturnLineFeed ? 1 : 0);
return true;
}
}