Compare commits

..

2 Commits

Author SHA1 Message Date
Alexandre Mutel
98c687b4ed Merge pull request #666 from meziantou/issues/665
Fix ANE when parsing empty documents with trackTrivia enabled
2022-09-27 07:24:22 +02:00
Gérald Barré
8e4a732efe Fix ANE when parsing empty documents with trackTrivia enabled 2022-09-26 21:55:28 -04:00
2 changed files with 15 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Markdig.Extensions.JiraLinks;
using Markdig.Renderers.Roundtrip;
using Markdig.Syntax;
using NUnit.Framework;
@@ -67,6 +68,15 @@ namespace Markdig.Tests
TestDescendantsOrder.TestSchemas(specsSyntaxTrees);
}
[Test]
public void ParseEmptyDocumentWithTrackTriviaEnabled()
{
var document = Markdown.Parse("", trackTrivia: true);
using var sw = new StringWriter();
new RoundtripRenderer(sw).Render(document);
Assert.AreEqual("", sw.ToString());
}
public static void TestSpec(string inputText, string expectedOutputText, string extensions = null, bool plainText = false, string context = null)
{
context ??= string.Empty;

View File

@@ -65,7 +65,11 @@ namespace Markdig.Parsers
var noBlocksFoundBlock = new EmptyBlock(null);
List<StringSlice> linesBefore = blockProcessor.UseLinesBefore();
noBlocksFoundBlock.LinesAfter = new List<StringSlice>();
noBlocksFoundBlock.LinesAfter.AddRange(linesBefore);
if (linesBefore != null)
{
noBlocksFoundBlock.LinesAfter.AddRange(linesBefore);
}
document.Add(noBlocksFoundBlock);
}
else if (lastBlock != null && blockProcessor.LinesBefore != null)