Skip to content

Commit

Permalink
Merge pull request #760 from zickb/fix_source_span_calculation_for_li…
Browse files Browse the repository at this point in the history
…nebreak_inline

Fix source span calculation for LineBreakInline
  • Loading branch information
xoofx committed Dec 14, 2023
2 parents 040a778 + 6f1dce6 commit a092ec2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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

0 comments on commit a092ec2

Please sign in to comment.