Add support for escape characters for normalize (#155)

This commit is contained in:
Alexandre Mutel
2017-10-27 18:30:32 +02:00
parent e15745f346
commit 6717be5210
5 changed files with 17 additions and 3 deletions

View File

@@ -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

View File

@@ -20,9 +20,8 @@ namespace Markdig.Renderers.Normalize.Inlines
{
if (obj.IsHard)
{
renderer.Write(" ");
renderer.Write(obj.IsBackslash ? "\\" : " ");
}
renderer.WriteLine();
}
}

View File

@@ -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);
}
}

View File

@@ -10,5 +10,7 @@ namespace Markdig.Syntax.Inlines
public class LineBreakInline : LeafInline
{
public bool IsHard { get; set; }
public bool IsBackslash { get; set; }
}
}

View File

@@ -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();