mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-17 18:00:55 +00:00
fix optional space after Atx heading leaders
This commit is contained in:
@@ -482,5 +482,22 @@ namespace Markdig.Helpers
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Overlaps(StringSlice other)
|
||||
{
|
||||
if (Length == 0 || other.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (other.End >= Start)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (other.Start <= End)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,10 +72,16 @@ namespace Markdig.Parsers
|
||||
// A space is required after leading #
|
||||
if (leadingCount > 0 && leadingCount <= MaxLeadingCount && (c.IsSpaceOrTab() || c == '\0'))
|
||||
{
|
||||
StringSlice whitespace = StringSlice.Empty;
|
||||
if (c.IsSpaceOrTab())
|
||||
{
|
||||
whitespace = new StringSlice(processor.Line.Text, processor.Start + leadingCount, processor.Start + leadingCount);
|
||||
}
|
||||
// Move to the content
|
||||
var headingBlock = new HeadingBlock(this)
|
||||
{
|
||||
HeaderChar = matchingChar,
|
||||
WhitespaceAfterAtxHeaderChar = whitespace,
|
||||
Level = leadingCount,
|
||||
Column = column,
|
||||
Span = { Start = sourcePosition },
|
||||
@@ -129,7 +135,14 @@ namespace Markdig.Parsers
|
||||
|
||||
// Setup the source end position of this element
|
||||
headingBlock.Span.End = processor.Line.End;
|
||||
headingBlock.AfterWhitespace = new StringSlice(processor.Line.Text, processor.Line.End + 1, sourceEnd);
|
||||
|
||||
var wsa = new StringSlice(processor.Line.Text, processor.Line.End + 1, sourceEnd);
|
||||
headingBlock.AfterWhitespace = wsa;
|
||||
if (wsa.Overlaps(headingBlock.WhitespaceAfterAtxHeaderChar))
|
||||
{
|
||||
// prevent double whitespace allocation in case of closing # i.e. "# #"
|
||||
headingBlock.WhitespaceAfterAtxHeaderChar = StringSlice.Empty;
|
||||
}
|
||||
|
||||
// We expect a single line, so don't continue
|
||||
return BlockState.Break;
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace Markdig.Renderers.Normalize
|
||||
: new string('#', obj.Level);
|
||||
|
||||
renderer.Write(obj.BeforeWhitespace);
|
||||
renderer.Write(headingText).Write(' ');
|
||||
renderer.Write(headingText);
|
||||
renderer.Write(obj.WhitespaceAfterAtxHeaderChar);
|
||||
renderer.WriteLeafInline(obj);
|
||||
renderer.Write(obj.AfterWhitespace);
|
||||
renderer.WriteLine(obj.Newline);
|
||||
|
||||
@@ -38,5 +38,8 @@ namespace Markdig.Syntax
|
||||
public int HeaderCharCount { get; set; }
|
||||
|
||||
public Newline SetextNewline { get; set; }
|
||||
|
||||
// space is mandatory after # only when there is heading content. I.e. "#" is valid
|
||||
public StringSlice WhitespaceAfterAtxHeaderChar { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user