mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 17:30:52 +00:00
fix CodeInline parsing & rendering
This commit is contained in:
@@ -11,26 +11,28 @@ namespace Markdig.Tests.RoundtripSpecs.Inlines
|
||||
[TestCase("`` ")]
|
||||
[TestCase(" `` ")]
|
||||
|
||||
[TestCase("`a`")]
|
||||
[TestCase(" `a`")]
|
||||
[TestCase("`a` ")]
|
||||
[TestCase(" `a` ")]
|
||||
[TestCase("`c`")]
|
||||
[TestCase(" `c`")]
|
||||
[TestCase("`c` ")]
|
||||
[TestCase(" `c` ")]
|
||||
|
||||
[TestCase("` a`")]
|
||||
[TestCase(" ` a`")]
|
||||
[TestCase("` a` ")]
|
||||
[TestCase(" ` a` ")]
|
||||
[TestCase("` c`")]
|
||||
[TestCase(" ` c`")]
|
||||
[TestCase("` c` ")]
|
||||
[TestCase(" ` c` ")]
|
||||
|
||||
[TestCase("`a `")]
|
||||
[TestCase(" `a `")]
|
||||
[TestCase("`a ` ")]
|
||||
[TestCase(" `a ` ")]
|
||||
|
||||
[TestCase("``a``")]
|
||||
[TestCase("- ```a```")]
|
||||
[TestCase("p ```a``` p")]
|
||||
[TestCase("`c `")]
|
||||
[TestCase(" `c `")]
|
||||
[TestCase("`c ` ")]
|
||||
[TestCase(" `c ` ")]
|
||||
|
||||
[TestCase("``c``")]
|
||||
[TestCase("```c```")]
|
||||
[TestCase("````c````")]
|
||||
|
||||
[TestCase("p `a` p")]
|
||||
[TestCase("p ``a`` p")]
|
||||
[TestCase("p ```a``` p")]
|
||||
|
||||
// broken
|
||||
//[TestCase("```a```")]
|
||||
@@ -41,10 +43,15 @@ namespace Markdig.Tests.RoundtripSpecs.Inlines
|
||||
|
||||
/// <see cref="CodeInlineParser"/>: intentionally trimmed. TODO: decide on how to handle
|
||||
//[TestCase("` a `")]
|
||||
//[TestCase(" ` a `")]
|
||||
//[TestCase("` a ` ")]
|
||||
//[TestCase(" ` a ` ")]
|
||||
public void Test_CodeInline(string value)
|
||||
[TestCase(" ` a `")]
|
||||
[TestCase("` a ` ")]
|
||||
[TestCase(" ` a ` ")]
|
||||
public void Test(string value)
|
||||
{
|
||||
RoundTrip(value);
|
||||
}
|
||||
|
||||
public void TestParagraph(string value)
|
||||
{
|
||||
RoundTrip(value);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace Markdig.Tests.RoundtripSpecs
|
||||
RoundTrip(value);
|
||||
}
|
||||
|
||||
[TestCase("- ```a```")]
|
||||
[TestCase("- i1\n - i1.1\n ```\n code\n ```")]
|
||||
public void TestCodeBlock(string value)
|
||||
{
|
||||
|
||||
@@ -95,6 +95,10 @@ namespace Markdig.Parsers
|
||||
for (int i = line.Start; i <= line.End; i++)
|
||||
{
|
||||
char c = line.Text[i];
|
||||
if (c == '`')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (state)
|
||||
{
|
||||
case ParseState.AfterFence:
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace Markdig.Parsers.Inlines
|
||||
}
|
||||
|
||||
bool isMatching = false;
|
||||
bool firstAndLastWasSpace = false;
|
||||
if (closeSticks == openSticks)
|
||||
{
|
||||
string content;
|
||||
@@ -95,6 +96,7 @@ namespace Markdig.Parsers.Inlines
|
||||
if (!allSpace && builder.Length > 2 && builder[0] == ' ' && builder[builder.Length - 1] == ' ')
|
||||
{
|
||||
content = builder.ToString(1, builder.Length - 2);
|
||||
firstAndLastWasSpace = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,7 +111,8 @@ namespace Markdig.Parsers.Inlines
|
||||
Span = new SourceSpan(processor.GetSourcePosition(startPosition, out int line, out int column), processor.GetSourcePosition(slice.Start - 1)),
|
||||
Line = line,
|
||||
Column = column,
|
||||
DelimiterCount = delimiterCount
|
||||
DelimiterCount = delimiterCount,
|
||||
FirstAndLastWasSpace = firstAndLastWasSpace
|
||||
};
|
||||
isMatching = true;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ namespace Markdig.Renderers.Normalize.Inlines
|
||||
//}
|
||||
var delimiterRun = new string(obj.Delimiter, obj.DelimiterCount);
|
||||
renderer.Write(delimiterRun);
|
||||
if (obj.FirstAndLastWasSpace)
|
||||
{
|
||||
renderer.Write(' ');
|
||||
}
|
||||
if (obj.Content.Length != 0)
|
||||
{
|
||||
if (obj.Content[0] == obj.Delimiter)
|
||||
@@ -48,6 +52,10 @@ namespace Markdig.Renderers.Normalize.Inlines
|
||||
{
|
||||
renderer.Write(' ');
|
||||
}
|
||||
if (obj.FirstAndLastWasSpace)
|
||||
{
|
||||
renderer.Write(' ');
|
||||
}
|
||||
renderer.Write(delimiterRun);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace Markdig.Renderers.Normalize
|
||||
renderer.RenderLinesBefore(paragraph);
|
||||
renderer.Write(paragraph.BeforeWhitespace);
|
||||
renderer.WriteLeafInline(paragraph);
|
||||
//renderer.FinishBlock();
|
||||
renderer.RenderLineAfterIfNeeded(paragraph);
|
||||
renderer.RenderLinesAfter(paragraph);
|
||||
}
|
||||
|
||||
@@ -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 System.Diagnostics;
|
||||
|
||||
namespace Markdig.Syntax.Inlines
|
||||
@@ -28,5 +29,6 @@ namespace Markdig.Syntax.Inlines
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
public bool FirstAndLastWasSpace { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user