mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 09:20:40 +00:00
fix HardLineBreak, CodeInline tests
This commit is contained in:
@@ -35,6 +35,7 @@ namespace Markdig.Parsers.Inlines
|
||||
|
||||
// Match the opened sticks
|
||||
int openSticks = slice.CountAndSkipChar(match);
|
||||
int contentStart = slice.Start;
|
||||
int closeSticks = 0;
|
||||
|
||||
char c = slice.CurrentChar;
|
||||
@@ -53,6 +54,7 @@ namespace Markdig.Parsers.Inlines
|
||||
// whitespace from the opening or closing backtick strings.
|
||||
|
||||
bool allSpace = true;
|
||||
var contentEnd = -1;
|
||||
|
||||
while (c != '\0')
|
||||
{
|
||||
@@ -64,6 +66,7 @@ namespace Markdig.Parsers.Inlines
|
||||
|
||||
if (c == match)
|
||||
{
|
||||
contentEnd = slice.Start;
|
||||
closeSticks = slice.CountAndSkipChar(match);
|
||||
|
||||
if (openSticks == closeSticks)
|
||||
@@ -87,7 +90,6 @@ namespace Markdig.Parsers.Inlines
|
||||
}
|
||||
|
||||
bool isMatching = false;
|
||||
bool firstAndLastWasSpace = false;
|
||||
if (closeSticks == openSticks)
|
||||
{
|
||||
string content;
|
||||
@@ -96,7 +98,6 @@ 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
|
||||
{
|
||||
@@ -104,15 +105,17 @@ namespace Markdig.Parsers.Inlines
|
||||
}
|
||||
|
||||
int delimiterCount = Math.Min(openSticks, closeSticks);
|
||||
var spanStart = processor.GetSourcePosition(startPosition, out int line, out int column);
|
||||
var spanEnd = processor.GetSourcePosition(slice.Start - 1);
|
||||
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)),
|
||||
ContentWithTrivia = new StringSlice(slice.Text, contentStart, contentEnd - 1),
|
||||
Span = new SourceSpan(spanStart, spanEnd),
|
||||
Line = line,
|
||||
Column = column,
|
||||
DelimiterCount = delimiterCount,
|
||||
FirstAndLastWasSpace = firstAndLastWasSpace
|
||||
};
|
||||
isMatching = true;
|
||||
}
|
||||
|
||||
@@ -41,15 +41,21 @@ namespace Markdig.Parsers.Inlines
|
||||
}
|
||||
|
||||
// A backslash at the end of the line is a [hard line break]:
|
||||
if (c == '\n')
|
||||
if (c == '\n' || c == '\r')
|
||||
{
|
||||
var newline = c == '\n' ? Newline.LineFeed : Newline.CarriageReturn;
|
||||
if (c == '\r' && slice.PeekChar() == '\n')
|
||||
{
|
||||
newline = Newline.CarriageReturnLineFeed;
|
||||
}
|
||||
processor.Inline = new LineBreakInline()
|
||||
{
|
||||
IsHard = true,
|
||||
IsBackslash = true,
|
||||
Span = { Start = processor.GetSourcePosition(startPosition, out line, out column) },
|
||||
Line = line,
|
||||
Column = column
|
||||
Column = column,
|
||||
Newline = newline
|
||||
};
|
||||
processor.Inline.Span.End = processor.Inline.Span.Start + 1;
|
||||
slice.NextChar();
|
||||
|
||||
@@ -16,17 +16,9 @@ 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)
|
||||
{
|
||||
renderer.Write(obj.Content);
|
||||
}
|
||||
if (obj.FirstAndLastWasSpace)
|
||||
{
|
||||
renderer.Write(' ');
|
||||
renderer.Write(obj.ContentWithTrivia);
|
||||
}
|
||||
renderer.Write(delimiterRun);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace Markdig.Syntax.Inlines
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
public StringSlice ContentWithTrivia { get; set; }
|
||||
|
||||
public bool FirstAndLastWasSpace { get; set; }
|
||||
}
|
||||
}
|
||||
12
src/Markdig/Syntax/Inlines/EscapedCharacterInline.cs
Normal file
12
src/Markdig/Syntax/Inlines/EscapedCharacterInline.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Markdig.Syntax.Inlines
|
||||
{
|
||||
[DebuggerDisplay("\\{Character}")]
|
||||
public class EscapedCharacterInline : LeafInline
|
||||
{
|
||||
public char Character { get; set; }
|
||||
|
||||
public override string ToString() => $@"\\{Character}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user