mirror of
https://github.com/xoofx/markdig.git
synced 2026-10-08 22:57:51 +00:00
Fix many regressions
This commit is contained in:
@@ -240,7 +240,7 @@ namespace Textamina.Markdig.Formatters
|
||||
|
||||
protected void Write(HardlineBreakInline hardlineBreak)
|
||||
{
|
||||
writer.WriteConstant("<br />");
|
||||
writer.WriteLineConstant("<br />");
|
||||
}
|
||||
|
||||
protected void WriteChildren(ContainerInline containerInline)
|
||||
@@ -274,7 +274,7 @@ namespace Textamina.Markdig.Formatters
|
||||
inline = inline.NextSibling;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (leafBlock.Lines != null)
|
||||
{
|
||||
var lines = leafBlock.Lines;
|
||||
for (int i = 0; i < lines.Count; i++)
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace Textamina.Markdig.Parsers
|
||||
{
|
||||
return state.IsBlankLine && block != null ? BlockState.BreakDiscard : BlockState.None;
|
||||
}
|
||||
state.MoveTo(state.StartBeforeIndent + 4);
|
||||
return BlockState.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,12 +120,14 @@ namespace Textamina.Markdig.Parsers
|
||||
count--;
|
||||
}
|
||||
|
||||
if (count <=0 && line.TrimEnd())
|
||||
if (count <=0 && !state.IsCodeIndent && line.TrimEnd())
|
||||
{
|
||||
// Don't keep the last line
|
||||
return BlockState.BreakDiscard;
|
||||
}
|
||||
|
||||
state.MoveTo(state.StartBeforeIndent);
|
||||
|
||||
// Remove any indent spaces
|
||||
c = state.CurrentChar;
|
||||
var indentCount = fence.IndentCount;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Textamina.Markdig.Helpers;
|
||||
using Textamina.Markdig.Syntax;
|
||||
using Textamina.Markdig.Syntax.Inlines;
|
||||
|
||||
namespace Textamina.Markdig.Parsers.Inlines
|
||||
{
|
||||
@@ -20,6 +21,17 @@ namespace Textamina.Markdig.Parsers.Inlines
|
||||
return false;
|
||||
}
|
||||
|
||||
// A line break (not in a code span or HTML tag) that is preceded by two or more spaces
|
||||
// and does not occur at the end of a block is parsed as a hard line break (rendered in HTML as a <br /> tag)
|
||||
var literal = state.Inline as LiteralInline;
|
||||
if (literal != null)
|
||||
{
|
||||
literal.TrimEnd = true;
|
||||
}
|
||||
|
||||
state.Inline = new HardlineBreakInline();
|
||||
text.NextChar(); // Skip \n
|
||||
|
||||
//// A line break (not in a code span or HTML tag) that is preceded by two or more spaces
|
||||
//// and does not occur at the end of a block is parsed as a hard line break (rendered in HTML as a <br /> tag)
|
||||
//var text = state.Lines;
|
||||
@@ -40,7 +52,7 @@ namespace Textamina.Markdig.Parsers.Inlines
|
||||
// return false;
|
||||
//}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,8 @@ namespace Textamina.Markdig.Parsers
|
||||
Block = leafBlock
|
||||
};
|
||||
|
||||
var text = new StringSlice(leafBlock.Lines.ToString());
|
||||
var text = new StringSlice(leafBlock.ToInlineText());
|
||||
leafBlock.Lines = null;
|
||||
|
||||
while (!text.IsEndOfSlice)
|
||||
{
|
||||
@@ -254,8 +255,11 @@ namespace Textamina.Markdig.Parsers
|
||||
{
|
||||
Log.WriteLine("** Dump before Emphasis:");
|
||||
leafBlock.Inline.DumpTo(Log);
|
||||
EmphasisInline.ProcessEmphasis(leafBlock.Inline);
|
||||
}
|
||||
EmphasisInline.ProcessEmphasis(leafBlock.Inline);
|
||||
|
||||
if (Log != null)
|
||||
{
|
||||
Log.WriteLine();
|
||||
Log.WriteLine("** Dump after Emphasis:");
|
||||
leafBlock.Inline.DumpTo(Log);
|
||||
|
||||
@@ -41,7 +41,11 @@ namespace Textamina.Markdig.Parsers
|
||||
var lineCount = lines.Count;
|
||||
for (int i = 0; i < lineCount; i++)
|
||||
{
|
||||
lines.Slices[i].Trim();
|
||||
lines.Slices[i].TrimStart();
|
||||
}
|
||||
if (lineCount > 0)
|
||||
{
|
||||
lines.Slices[lineCount - 1].TrimEnd();
|
||||
}
|
||||
}
|
||||
else // if (heading?.Lines.Count > 1)
|
||||
|
||||
@@ -11,8 +11,14 @@ namespace Textamina.Markdig.Syntax
|
||||
{
|
||||
public HeadingBlock(BlockParser parser) : base(parser)
|
||||
{
|
||||
ProcessInlines = true;
|
||||
}
|
||||
|
||||
public int Level { get; set; }
|
||||
|
||||
public override string ToInlineText()
|
||||
{
|
||||
return Lines.ToString(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,16 @@ namespace Textamina.Markdig.Syntax.Inlines
|
||||
|
||||
public string Content { get; set; }
|
||||
|
||||
public bool TrimEnd { get; set; }
|
||||
|
||||
protected override void Close(InlineParserState state)
|
||||
{
|
||||
Content = HtmlHelper.Unescape(ContentBuilder.ToString(), false);
|
||||
var str = ContentBuilder.ToString();
|
||||
if (TrimEnd)
|
||||
{
|
||||
str = str.TrimEnd();
|
||||
}
|
||||
Content = HtmlHelper.Unescape(str, false);
|
||||
state.StringBuilders.Release(ContentBuilder);
|
||||
ContentBuilder = null;
|
||||
}
|
||||
|
||||
@@ -26,5 +26,10 @@ namespace Textamina.Markdig.Syntax
|
||||
}
|
||||
Lines.Append(ref line);
|
||||
}
|
||||
|
||||
public virtual string ToInlineText()
|
||||
{
|
||||
return Lines.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,12 +48,18 @@ namespace Textamina.Markdig.Syntax
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return ToString(false);
|
||||
}
|
||||
|
||||
public string ToString(bool replaceEndOfLineBySpace)
|
||||
{
|
||||
var newLine = replaceEndOfLineBySpace ? ' ' : '\n';
|
||||
var builder = StringBuilderCache.Local();
|
||||
for(int i = 0; i < Count; i++)
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
builder.Append('\n');
|
||||
builder.Append(newLine);
|
||||
}
|
||||
builder.Append(Slices[i].Text, Slices[i].Start, Slices[i].Length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user