mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-09 05:49:12 +00:00
Add support for escape characters for normalize (#155)
This commit is contained in:
@@ -31,7 +31,8 @@ namespace Markdig.Parsers.Inlines
|
||||
Content = new StringSlice(slice.Text, slice.Start, slice.Start),
|
||||
Span = { Start = processor.GetSourcePosition(startPosition, out line, out column) },
|
||||
Line = line,
|
||||
Column = column
|
||||
Column = column,
|
||||
IsFirstCharacterEscaped = true,
|
||||
};
|
||||
processor.Inline.Span.End = processor.Inline.Span.Start + 1;
|
||||
slice.NextChar();
|
||||
@@ -44,6 +45,7 @@ namespace Markdig.Parsers.Inlines
|
||||
processor.Inline = new LineBreakInline()
|
||||
{
|
||||
IsHard = true,
|
||||
IsBackslash = true,
|
||||
Span = { Start = processor.GetSourcePosition(startPosition, out line, out column) },
|
||||
Line = line,
|
||||
Column = column
|
||||
|
||||
@@ -20,9 +20,8 @@ namespace Markdig.Renderers.Normalize.Inlines
|
||||
{
|
||||
if (obj.IsHard)
|
||||
{
|
||||
renderer.Write(" ");
|
||||
renderer.Write(obj.IsBackslash ? "\\" : " ");
|
||||
}
|
||||
|
||||
renderer.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// 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.Syntax.Inlines;
|
||||
|
||||
namespace Markdig.Renderers.Normalize.Inlines
|
||||
@@ -13,6 +15,10 @@ namespace Markdig.Renderers.Normalize.Inlines
|
||||
{
|
||||
protected override void Write(NormalizeRenderer renderer, LiteralInline obj)
|
||||
{
|
||||
if (obj.IsFirstCharacterEscaped && obj.Content.Length > 0 && obj.Content[obj.Content.Start].IsAsciiPunctuation())
|
||||
{
|
||||
renderer.Write('\\');
|
||||
}
|
||||
renderer.Write(ref obj.Content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,7 @@ namespace Markdig.Syntax.Inlines
|
||||
public class LineBreakInline : LeafInline
|
||||
{
|
||||
public bool IsHard { get; set; }
|
||||
|
||||
public bool IsBackslash { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,11 @@ namespace Markdig.Syntax.Inlines
|
||||
/// </summary>
|
||||
public StringSlice Content;
|
||||
|
||||
/// <summary>
|
||||
/// A boolean indicating whether the first character of this literal is escaped by `\`.
|
||||
/// </summary>
|
||||
public bool IsFirstCharacterEscaped { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Content.ToString();
|
||||
|
||||
Reference in New Issue
Block a user