improve whitespace handling in FencedCodeBlock

This commit is contained in:
Ruud Poutsma
2020-10-24 14:13:38 +02:00
parent db2856daf7
commit 1b44256fc0
7 changed files with 22 additions and 9 deletions

View File

@@ -104,12 +104,20 @@ namespace Markdig.Tests.RoundtripSpecs
[TestCase("1. i\n2. j\n3. k")]
[TestCase("1. i\n2. j\n3. k\n")]
public void Test(string value)
{
RoundTrip(value);
}
[TestCase("10. i")]
[TestCase("11. i")]
[TestCase("10. i\n12. i")]
public void Test_MoreThenOneStart(string value)
{
RoundTrip(value);
}
[TestCase("\n1. i")]
[TestCase("\r1. i")]
[TestCase("\r\n1. i")]

View File

@@ -90,6 +90,8 @@ namespace Markdig.Parsers
// after args?
// info: between fencedchars and
var wsb = blockProcessor.PopBeforeWhitespace(blockProcessor.Start - 1);
// An info string cannot contain any backticks (unless it is a tilde block)
for (int i = line.Start; i <= line.End; i++)
{
@@ -166,6 +168,7 @@ namespace Markdig.Parsers
fenced.Arguments = HtmlHelper.Unescape(arg);
fenced.WhitespaceAfterArguments = afterArg;
fenced.InfoNewline = line.Newline;
fenced.BeforeWhitespace = wsb;
return true;
}

View File

@@ -84,7 +84,7 @@ namespace Markdig.Parsers
WhitespaceAfterAtxHeaderChar = whitespace,
Level = leadingCount,
Column = column,
Span = { Start = sourcePosition },
Span = { Start = sourcePosition },
BeforeWhitespace = processor.PopBeforeWhitespace(sourcePosition - 1),
LinesBefore = processor.UseLinesBefore(),
Newline = processor.Line.Newline,

View File

@@ -114,13 +114,10 @@ namespace Markdig.Parsers
// If this is the end of file and the last line is empty
if (lineText.Text is null)
{
if (!lineReader.IsEndOfFile())
var lastBlock = blockProcessor.LastBlock;
if (lastBlock != null && blockProcessor.BeforeLines != null)
{
var lastBlock = blockProcessor.LastBlock;
if (lastBlock != null && blockProcessor.BeforeLines != null)
{
lastBlock.LinesAfter = blockProcessor.BeforeLines ?? new List<StringSlice>();
}
lastBlock.LinesAfter = blockProcessor.BeforeLines ?? new List<StringSlice>();
}
break;
}

View File

@@ -44,6 +44,7 @@ namespace Markdig.Renderers.Normalize
renderer.Write(listItem.BeforeWhitespace);
renderer.Write(index.ToString(CultureInfo.InvariantCulture));
//renderer.Write(listItem.Order.ToString(CultureInfo.InvariantCulture));
renderer.Write(listBlock.OrderedDelimiter);
renderer.Write(' ');
renderer.PushIndent(new string(' ', IntLog10Fast(index) + 3));

View File

@@ -2,6 +2,7 @@
// 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;
using Markdig.Parsers;
namespace Markdig.Syntax
@@ -56,5 +57,9 @@ namespace Markdig.Syntax
/// Occurs when the process of inlines ends for this instance.
/// </summary>
event ProcessInlineDelegate ProcessInlinesEnd;
public StringSlice BeforeWhitespace { get; set; }
public StringSlice AfterWhitespace { get; set; }
}
}

View File

@@ -51,7 +51,6 @@ namespace Markdig.Syntax
/// </summary>
public int ClosingFencedCharCount { get; set; }
public StringSlice WhitespaceBeforeClosingFence { get; set; }
public StringSlice AfterWhitespace { get; set; }
/// <summary>
/// Gets or sets the fenced character used to open and close this fenced code block.