From 5e4a917dbd25c6c40e2d184cfaca908c2908aca5 Mon Sep 17 00:00:00 2001 From: Sergey Nozhenko Date: Wed, 18 Dec 2024 12:38:13 +0300 Subject: [PATCH 1/3] Fixes an error in the AbbreviationParser. --- src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs b/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs index 863e882f..0b9548b1 100644 --- a/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs +++ b/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs @@ -171,7 +171,7 @@ private void DocumentOnProcessInlinesBegin(InlineProcessor inlineProcessor, Inli // Process the remaining literal literal = new LiteralInline() { - Span = new SourceSpan(abbrInline.Span.End + 1, literal.Span.End), + Span = new SourceSpan(abbrInline.Span.End + 1, container.Span.End), Line = line, Column = column + match.Length, }; From 2cff6c51949324ace802cf0a5880160fa2627470 Mon Sep 17 00:00:00 2001 From: Sergey Nozhenko Date: Wed, 18 Dec 2024 13:09:00 +0300 Subject: [PATCH 2/3] It's necessary to keep a copy of the original literal.Span.End, because otherwise it is just lost in some cases. --- src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs b/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs index 0b9548b1..9cfe5b10 100644 --- a/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs +++ b/src/Markdig/Extensions/Abbreviations/AbbreviationParser.cs @@ -89,6 +89,7 @@ private void DocumentOnProcessInlinesBegin(InlineProcessor inlineProcessor, Inli { var literal = (LiteralInline)processor.Inline!; var originalLiteral = literal; + var originalSpanEnd = literal.Span.End; ContainerInline? container = null; @@ -171,7 +172,7 @@ private void DocumentOnProcessInlinesBegin(InlineProcessor inlineProcessor, Inli // Process the remaining literal literal = new LiteralInline() { - Span = new SourceSpan(abbrInline.Span.End + 1, container.Span.End), + Span = new SourceSpan(abbrInline.Span.End + 1, originalSpanEnd), Line = line, Column = column + match.Length, }; From bc41b0c2a33278489319ff9fa0c0c4c9ca1f7ba1 Mon Sep 17 00:00:00 2001 From: Sergey Nozhenko Date: Thu, 19 Dec 2024 00:44:29 +0300 Subject: [PATCH 3/3] Existing test has been extended. --- src/Markdig.Tests/TestSourcePosition.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Markdig.Tests/TestSourcePosition.cs b/src/Markdig.Tests/TestSourcePosition.cs index 746694eb..2a7b8acd 100644 --- a/src/Markdig.Tests/TestSourcePosition.cs +++ b/src/Markdig.Tests/TestSourcePosition.cs @@ -533,13 +533,17 @@ public void TestHtmlEntityInline() [Test] public void TestAbbreviations() { - Check("*[HTML]: Hypertext Markup Language\r\n\r\nLater in a text we are using HTML and it becomes an abbr tag HTML", @" + Check("*[HTML]: Hypertext Markup Language\r\n\r\nLater in a text we are using HTML and it becomes an abbr tag HTML\r\n\r\nHTML abbreviation at the beginning of a line", @" paragraph ( 2, 0) 38-102 container ( 2, 0) 38-102 literal ( 2, 0) 38-66 abbreviation ( 2,29) 67-70 literal ( 2,33) 71-98 abbreviation ( 2,61) 99-102 +paragraph ( 4, 0) 107-150 +container ( 4, 0) 107-150 +abbreviation ( 4, 0) 107-110 +literal ( 4, 4) 111-150 ", "abbreviations"); }