diff --git a/src/Markdig.Tests/TestEmphasisPlus.cs b/src/Markdig.Tests/TestEmphasisPlus.cs index 9c2fdc776..fda75236b 100644 --- a/src/Markdig.Tests/TestEmphasisPlus.cs +++ b/src/Markdig.Tests/TestEmphasisPlus.cs @@ -1,7 +1,10 @@ // Copyright (c) Alexandre Mutel. All rights reserved. -// This file is licensed under the BSD-Clause 2 license. +// This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. +using Markdig.Syntax; +using Markdig.Syntax.Inlines; + namespace Markdig.Tests; [TestFixture] @@ -18,4 +21,17 @@ public void NormalStrongNormal() { TestParser.TestSpec("normal ***Strong emphasis*** normal", "

normal Strong emphasis normal

", ""); } + + [Test] + public void OpenEmphasisHasConvenientContentStringSlice() + { + var pipeline = new MarkdownPipelineBuilder().Build(); + + var document = Markdown.Parse("test*test", pipeline); + + var emphasisDelimiterLiteral = (LiteralInline)((ParagraphBlock)document.LastChild).Inline.ElementAt(1); + Assert.That(emphasisDelimiterLiteral.Content.Text == "test*test"); + Assert.That(emphasisDelimiterLiteral.Content.Start == 4); + Assert.That(emphasisDelimiterLiteral.Content.End == 4); + } } \ No newline at end of file diff --git a/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs b/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs index 11915dba7..599aca3b3 100644 --- a/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs +++ b/src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs @@ -1,5 +1,5 @@ // Copyright (c) Alexandre Mutel. All rights reserved. -// This file is licensed under the BSD-Clause 2 license. +// This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. using System.Diagnostics; @@ -109,7 +109,7 @@ public bool PostProcess(InlineProcessor state, Inline? root, Inline? lastChild, var child = container.FirstChild; while (child != null) { - // Stop the search on the delimitation child + // Stop the search on the delimitation child if (child == lastChild) { break; @@ -197,7 +197,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice) if (canOpen) delimiterType |= DelimiterType.Open; if (canClose) delimiterType |= DelimiterType.Close; - var delimiter = new EmphasisDelimiterInline(this, emphasisDesc) + var delimiter = new EmphasisDelimiterInline(this, emphasisDesc, new StringSlice(slice.Text, startPosition, slice.Start - 1)) { DelimiterCount = delimiterCount, Type = delimiterType, @@ -221,7 +221,7 @@ private void ProcessEmphasis(InlineProcessor processor, List= openDelimiterIndex + 1; k--) { var literalDelimiter = delimiters[k]; - literalDelimiter.ReplaceBy(literalDelimiter.AsLiteralInline()); + literalDelimiter.ReplaceBy(literalDelimiter.AsLiteralInline()); delimiters.RemoveAt(k); i--; } diff --git a/src/Markdig/Syntax/Inlines/EmphasisDelimiterInline.cs b/src/Markdig/Syntax/Inlines/EmphasisDelimiterInline.cs index aa70896e3..b472eb441 100644 --- a/src/Markdig/Syntax/Inlines/EmphasisDelimiterInline.cs +++ b/src/Markdig/Syntax/Inlines/EmphasisDelimiterInline.cs @@ -1,5 +1,5 @@ // Copyright (c) Alexandre Mutel. All rights reserved. -// This file is licensed under the BSD-Clause 2 license. +// This file is licensed under the BSD-Clause 2 license. // See the license.txt file in the project root for more information. using Markdig.Helpers; @@ -27,6 +27,24 @@ public EmphasisDelimiterInline(InlineParser parser, EmphasisDescriptor descripto Descriptor = descriptor; DelimiterChar = descriptor.Character; + Content = new StringSlice(ToLiteral()); + } + + /// + /// Initializes a new instance of the class. + /// + /// The parser. + /// The descriptor. + /// The content. + /// + internal EmphasisDelimiterInline(InlineParser parser, EmphasisDescriptor descriptor, StringSlice content) : base(parser) + { + if (descriptor is null) + ThrowHelper.ArgumentNullException(nameof(descriptor)); + + Descriptor = descriptor; + DelimiterChar = descriptor.Character; + Content = content; } /// @@ -44,6 +62,11 @@ public EmphasisDelimiterInline(InlineParser parser, EmphasisDescriptor descripto /// public int DelimiterCount { get; set; } + /// + /// The content as a . + /// + public StringSlice Content; + public override string ToLiteral() { return DelimiterCount > 0 ? new string(DelimiterChar, DelimiterCount) : string.Empty; @@ -53,7 +76,7 @@ public LiteralInline AsLiteralInline() { return new LiteralInline() { - Content = new StringSlice(ToLiteral()), + Content = Content, IsClosed = true, Span = Span, Line = Line,