mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-18 10:21:28 +00:00
Don't create an empty LiteralInline when trimming spaces at the end of a line (issue #42)
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
// This file is licensed under the BSD-Clause 2 license.
|
// This file is licensed under the BSD-Clause 2 license.
|
||||||
// See the license.txt file in the project root for more information.
|
// See the license.txt file in the project root for more information.
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Markdig.Syntax;
|
||||||
|
using Markdig.Syntax.Inlines;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace Markdig.Tests
|
namespace Markdig.Tests
|
||||||
@@ -27,6 +30,17 @@ Later in a text we are using HTML and it becomes an abbr tag HTML
|
|||||||
Console.WriteLine(result);
|
Console.WriteLine(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestEmptyLiteral()
|
||||||
|
{
|
||||||
|
var text = @"> *some text*
|
||||||
|
> some other text";
|
||||||
|
var doc = Markdown.Parse(text);
|
||||||
|
|
||||||
|
Assert.True(doc.Descendants().OfType<LiteralInline>().All(x => !x.Content.IsEmpty),
|
||||||
|
"There should not have any empty literals");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSelfPipeline1()
|
public void TestSelfPipeline1()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,13 +75,18 @@ namespace Markdig.Parsers.Inlines
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
processor.Inline = new LiteralInline()
|
// Create a new LiteralInline only if it is not empty
|
||||||
|
var newSlice = length > 0 ? new StringSlice(slice.Text, slice.Start, endPosition) : StringSlice.Empty;
|
||||||
|
if (!newSlice.IsEmpty)
|
||||||
{
|
{
|
||||||
Content = length > 0 ? new StringSlice(slice.Text, slice.Start, endPosition) : StringSlice.Empty,
|
processor.Inline = new LiteralInline()
|
||||||
Span = new SourceSpan(startPosition, processor.GetSourcePosition(endPosition)),
|
{
|
||||||
Line = line,
|
Content = length > 0 ? newSlice : StringSlice.Empty,
|
||||||
Column = column,
|
Span = new SourceSpan(startPosition, processor.GetSourcePosition(endPosition)),
|
||||||
};
|
Line = line,
|
||||||
|
Column = column,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
slice.Start = nextStart;
|
slice.Start = nextStart;
|
||||||
|
|||||||
Reference in New Issue
Block a user