Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source span calculation for LineBreakInline #760

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Markdig.Tests/TestSourcePosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,38 @@ public void TestParagraphWithEndNewLine()
", trackTrivia: true);
}


[Test]
public void TestMultipleParagraphsWithEndNewLine()
{
Check("0123456789\n\n0123456789\n\n", @"
paragraph ( 0, 0) 0-10
literal ( 0, 0) 0-9
linebreak ( 0,10) 10-10
paragraph ( 2, 0) 12-22
literal ( 2, 0) 12-21
linebreak ( 2,10) 22-22
", trackTrivia: true);

Check("0123456789\r\r0123456789\r\r", @"
paragraph ( 0, 0) 0-10
literal ( 0, 0) 0-9
linebreak ( 0,10) 10-10
paragraph ( 2, 0) 12-22
literal ( 2, 0) 12-21
linebreak ( 2,10) 22-22
", trackTrivia: true);

Check("0123456789\r\n\r\n0123456789\r\n\r\n", @"
paragraph ( 0, 0) 0-11
literal ( 0, 0) 0-9
linebreak ( 0,10) 10-11
paragraph ( 2, 0) 14-25
literal ( 2, 0) 14-23
linebreak ( 2,10) 24-25
", trackTrivia: true);
}

[Test]
public void TestEmphasis()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Markdig/Parsers/InlineProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void ProcessInlineLeaf(LeafBlock leafBlock)
previousLineIndexForSliceOffset = 0;
lineOffsets.Clear();
var text = leafBlock.Lines.ToSlice(lineOffsets);
var textEnd = text.Length;
var textEnd = text.End;
leafBlock.Lines.Release();
int previousStart = -1;

Expand Down Expand Up @@ -320,7 +320,7 @@ public void ProcessInlineLeaf(LeafBlock leafBlock)
var newLine = leafBlock.NewLine;
if (newLine != NewLine.None)
{
var position = GetSourcePosition(textEnd, out int line, out int column);
var position = GetSourcePosition(textEnd + 1, out int line, out int column);
leafBlock.Inline.AppendChild(new LineBreakInline { NewLine = newLine, Line = line, Column = column, Span = { Start = position, End = position + (newLine == NewLine.CarriageReturnLineFeed ? 1 : 0) } });
}
}
Expand Down
Loading