fix SetextHeading tests

This commit is contained in:
Ruud Poutsma
2020-10-18 13:08:40 +02:00
parent 225e308438
commit 810ae49cc7
4 changed files with 11 additions and 11 deletions

View File

@@ -41,6 +41,10 @@ namespace Markdig.Tests.RoundtripSpecs
[TestCase("h1\r===\r\n")]
[TestCase("h1\n===\r\n")]
[TestCase("h1\r\n===\r\n")]
[TestCase("h1\n===\n\n\nh2---\n\n")]
[TestCase("h1\r===\r\r\rh2---\r\r")]
[TestCase("h1\r\n===\r\n\r\n\r\nh2---\r\n\r\n")]
public void TestNewline(string value)
{
RoundTrip(value);

View File

@@ -180,21 +180,14 @@ namespace Markdig.Parsers
public int WhitespaceStart { get; set; }
// NOTE: Line.Text is full source, not the line (!)
public StringSlice PopBeforeWhitespace(int end)
{
// NOTE: Line.Text is full source, not the line (!)
var stringSlice = new StringSlice(Line.Text, WhitespaceStart, end);
WhitespaceStart = end + 1;
return stringSlice;
}
public StringSlice PopBeforeWhitespace(int start, int end)
{
var stringSlice = new StringSlice(Line.Text, start, end);
WhitespaceStart = end + 1;
return stringSlice;
}
public List<StringSlice> BeforeLines { get; set; }
public bool TrackTrivia { get => trackTrivia; set => trackTrivia = value; }

View File

@@ -209,6 +209,7 @@ namespace Markdig.Parsers
return BlockState.None;
}
var bulletLength = 1; // TODO: RTP: fix for ordered
var savedWhitespaceStart = state.WhitespaceStart;
var whitespaceBefore = state.PopBeforeWhitespace(state.Start - bulletLength - 1);
state.WhitespaceStart = state.Start;
@@ -231,6 +232,7 @@ namespace Markdig.Parsers
if (!c.IsSpaceOrTab())
{
state.GoToColumn(initColumn);
state.WhitespaceStart = savedWhitespaceStart; // restore changed WhitespaceStart state
return BlockState.None;
}
@@ -261,6 +263,7 @@ namespace Markdig.Parsers
state.IsOpen(previousParagraph) && listInfo.BulletType == '1' && listInfo.OrderedStart != "1")
{
state.GoToColumn(initColumn);
state.WhitespaceStart = savedWhitespaceStart; // restore changed WhitespaceStart state
return BlockState.None;
}
}

View File

@@ -115,15 +115,15 @@ namespace Markdig.Parsers
Span = new SourceSpan(paragraph.Span.Start, line.Start),
Level = level,
Lines = paragraph.Lines,
BeforeWhitespace = state.PopBeforeWhitespace(sourcePosition - 1),
BeforeWhitespace = state.PopBeforeWhitespace(sourcePosition - 1), // remove dashes
AfterWhitespace = new StringSlice(state.Line.Text, state.Start, line.End),
LinesBefore = state.UseLinesBefore(),
LinesBefore = paragraph.LinesBefore,
Newline = state.Line.Newline,
IsSetext = true,
HeaderCharCount = count,
SetextNewline = paragraph.Newline,
};
//heading.Lines.Trim();
//heading.Lines.Trim(); // TODO: RTP: fix
// Remove the paragraph as a pending block
state.NewBlocks.Push(heading);