mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 17:30:52 +00:00
fix broken newline parsing for LineBreakInline and PipeTableParser
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user