mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 09:20:40 +00:00
Merge pull request #560 from yufeih/yufeih/fix-crlf
Fix rendering diff between line endings
This commit is contained in:
@@ -115,9 +115,9 @@ namespace Markdig.Tests.RoundtripSpecs
|
||||
}
|
||||
|
||||
|
||||
//[TestCase("\n")]
|
||||
//[TestCase("\r\n")]
|
||||
//[TestCase("\r")]
|
||||
[TestCase("\n")]
|
||||
[TestCase("\r\n")]
|
||||
[TestCase("\r")]
|
||||
|
||||
[TestCase("p\n")]
|
||||
[TestCase("p\r")]
|
||||
|
||||
17
src/Markdig.Tests/TestNewLine.cs
Normal file
17
src/Markdig.Tests/TestNewLine.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Markdig.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestNewLine
|
||||
{
|
||||
[TestCase("a \nb", "<p>a<br />\nb</p>\n")]
|
||||
[TestCase("a\\\nb", "<p>a<br />\nb</p>\n")]
|
||||
[TestCase("a `b\nc`", "<p>a <code>b c</code></p>\n")]
|
||||
public void Test(string value, string expectedHtml)
|
||||
{
|
||||
Assert.AreEqual(expectedHtml, Markdown.ToHtml(value));
|
||||
Assert.AreEqual(expectedHtml, Markdown.ToHtml(value.Replace("\n", "\r\n")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// 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.
|
||||
|
||||
using Markdig.Helpers;
|
||||
@@ -63,6 +63,12 @@ namespace Markdig.Parsers.Inlines
|
||||
{
|
||||
c = ' ';
|
||||
}
|
||||
else if (c == '\r')
|
||||
{
|
||||
slice.SkipChar();
|
||||
c = slice.CurrentChar;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == match)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// 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.
|
||||
|
||||
using Markdig.Helpers;
|
||||
@@ -66,7 +66,7 @@ namespace Markdig.Parsers.Inlines
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == '\n')
|
||||
if (c == '\n' || c == '\r')
|
||||
{
|
||||
processor.Inline = new LineBreakInline()
|
||||
{
|
||||
|
||||
@@ -52,7 +52,8 @@ namespace Markdig.Parsers.Inlines
|
||||
length = nextStart - slice.Start;
|
||||
if (!processor.TrackTrivia)
|
||||
{
|
||||
if (text[nextStart] == '\n')
|
||||
var nextText = text[nextStart];
|
||||
if (nextText == '\n' || nextText == '\r')
|
||||
{
|
||||
int end = nextStart - 1;
|
||||
while (length > 0 && text[end].IsSpace())
|
||||
|
||||
Reference in New Issue
Block a user