allow CodeInline with multiple delimiter characters

This commit is contained in:
Ruud Poutsma
2020-09-25 19:23:11 +02:00
parent cadbc67825
commit acf2ba9502
4 changed files with 34 additions and 15 deletions

View File

@@ -360,6 +360,16 @@ namespace Markdig.Tests
[TestCase("`a ` ")]
[TestCase(" `a ` ")]
[TestCase("``a``")]
[TestCase("- ```a```")]
[TestCase("p ```a``` p")]
// broken
//[TestCase("```a```")]
[TestCase("```a``` p")]
//[TestCase("p\n\n```a``` p")]
//[TestCase("```a``` p\n```a``` p")]
/// <see cref="CodeInlineParser"/>: intentionally trimmed. TODO: decide on how to handle
//[TestCase("` a `")]
//[TestCase(" ` a `")]

View File

@@ -5,6 +5,7 @@
using Markdig.Helpers;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using System;
namespace Markdig.Parsers.Inlines
{
@@ -100,13 +101,15 @@ namespace Markdig.Parsers.Inlines
content = builder.ToString();
}
int delimiterCount = Math.Min(openSticks, closeSticks);
processor.Inline = new CodeInline()
{
Delimiter = match,
Content = content,
Span = new SourceSpan(processor.GetSourcePosition(startPosition, out int line, out int column), processor.GetSourcePosition(slice.Start - 1)),
Line = line,
Column = column
Column = column,
DelimiterCount = delimiterCount
};
isMatching = true;
}

View File

@@ -15,22 +15,22 @@ namespace Markdig.Renderers.Normalize.Inlines
protected override void Write(NormalizeRenderer renderer, CodeInline obj)
{
var delimiterCount = 0;
for (var i = 0; i < obj.Content.Length; i++)
{
var index = obj.Content.IndexOf(obj.Delimiter, i);
if (index == -1) break;
//for (var i = 0; i < obj.Content.Length; i++)
//{
// var index = obj.Content.IndexOf(obj.Delimiter, i);
// if (index == -1) break;
var count = 1;
for (i = index + 1; i < obj.Content.Length; i++)
{
if (obj.Content[i] == obj.Delimiter) count++;
else break;
}
// var count = 1;
// for (i = index + 1; i < obj.Content.Length; i++)
// {
// if (obj.Content[i] == obj.Delimiter) count++;
// else break;
// }
if (delimiterCount < count)
delimiterCount = count;
}
var delimiterRun = new string(obj.Delimiter, delimiterCount + 1);
// if (delimiterCount < count)
// delimiterCount = count;
//}
var delimiterRun = new string(obj.Delimiter, obj.DelimiterCount);
renderer.Write(delimiterRun);
if (obj.Content.Length != 0)
{

View File

@@ -18,9 +18,15 @@ namespace Markdig.Syntax.Inlines
/// </summary>
public char Delimiter { get; set; }
/// <summary>
/// Gets or sets the amount of delimiter characters used
/// </summary>
public int DelimiterCount { get; set; }
/// <summary>
/// Gets or sets the content of the span.
/// </summary>
public string Content { get; set; }
}
}