mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 17:30:52 +00:00
Add property handling of precise position for links
This commit is contained in:
@@ -3,10 +3,13 @@
|
||||
// See the license.txt file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Markdig.Helpers;
|
||||
using Markdig.Renderers.Html;
|
||||
using Markdig.Syntax;
|
||||
using Markdig.Syntax.Inlines;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Markdig.Tests
|
||||
@@ -162,6 +165,47 @@ literal ( 0, 4) 4-5
|
||||
");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLinkParts1()
|
||||
{
|
||||
// 0 1
|
||||
// 01 2 3456789012345
|
||||
var link = Markdown.Parse("0\n\n01 [234](/56)", new MarkdownPipelineBuilder().UsePreciseSourceLocation().Build()).Descendants().OfType<LinkInline>().FirstOrDefault();
|
||||
Assert.NotNull(link);
|
||||
|
||||
Assert.AreEqual(new SourceSpan(7, 9), link.LabelSpan);
|
||||
Assert.AreEqual(new SourceSpan(12, 14), link.UrlSpan);
|
||||
Assert.AreEqual(SourceSpan.Empty, link.TitleSpan);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLinkParts2()
|
||||
{
|
||||
// 0 1
|
||||
// 01 2 34567890123456789
|
||||
var link = Markdown.Parse("0\n\n01 [234](/56 'yo')", new MarkdownPipelineBuilder().UsePreciseSourceLocation().Build()).Descendants().OfType<LinkInline>().FirstOrDefault();
|
||||
Assert.NotNull(link);
|
||||
|
||||
Assert.AreEqual(new SourceSpan(7, 9), link.LabelSpan);
|
||||
Assert.AreEqual(new SourceSpan(12, 14), link.UrlSpan);
|
||||
Assert.AreEqual(new SourceSpan(16, 19), link.TitleSpan);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestLinkParts3()
|
||||
{
|
||||
// 0 1
|
||||
// 01 2 3456789012345
|
||||
var link = Markdown.Parse("0\n\n01", new MarkdownPipelineBuilder().UsePreciseSourceLocation().Build()).Descendants().OfType<LinkInline>().FirstOrDefault();
|
||||
Assert.NotNull(link);
|
||||
|
||||
Assert.AreEqual(new SourceSpan(5, 15), link.SourceSpan);
|
||||
Assert.AreEqual(new SourceSpan(7, 9), link.LabelSpan);
|
||||
Assert.AreEqual(new SourceSpan(12, 14), link.UrlSpan);
|
||||
Assert.AreEqual(SourceSpan.Empty, link.TitleSpan);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHtmlInline()
|
||||
{
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Markdig.Parsers.Inlines
|
||||
{
|
||||
Type = DelimiterType.Open,
|
||||
Label = label,
|
||||
LabelSpan = label != null ? processor.GetSourcePositionFromLocalSpan(labelSpan) : SourceSpan.Empty,
|
||||
LabelSpan = processor.GetSourcePositionFromLocalSpan(labelSpan),
|
||||
IsImage = isImage,
|
||||
SourceSpan = new SourceSpan(startPosition, processor.GetSourcePosition(slice.Start - 1)),
|
||||
Line = line,
|
||||
@@ -225,19 +225,13 @@ namespace Markdig.Parsers.Inlines
|
||||
Url = HtmlHelper.Unescape(url),
|
||||
Title = HtmlHelper.Unescape(title),
|
||||
IsImage = openParent.IsImage,
|
||||
LabelSpan = openParent.LabelSpan,
|
||||
UrlSpan = inlineState.GetSourcePositionFromLocalSpan(linkSpan),
|
||||
TitleSpan = inlineState.GetSourcePositionFromLocalSpan(titleSpan),
|
||||
SourceSpan = new SourceSpan(openParent.SourceSpan.Start, inlineState.GetSourcePosition(text.Start -1)),
|
||||
Line = openParent.Line,
|
||||
Column = openParent.Column,
|
||||
};
|
||||
if (url != null)
|
||||
{
|
||||
link.UrlSourceSpan = inlineState.GetSourcePositionFromLocalSpan(linkSpan);
|
||||
}
|
||||
|
||||
if (title != null)
|
||||
{
|
||||
link.TitleSourceSpan = inlineState.GetSourcePositionFromLocalSpan(titleSpan);
|
||||
}
|
||||
|
||||
openParent.ReplaceBy(link);
|
||||
// Notifies processor as we are creating an inline locally
|
||||
@@ -312,6 +306,7 @@ namespace Markdig.Parsers.Inlines
|
||||
|
||||
var literal = new LiteralInline()
|
||||
{
|
||||
SourceSpan = openParent.SourceSpan,
|
||||
Content = new StringSlice(openParent.IsImage ? "![" : "[")
|
||||
};
|
||||
|
||||
|
||||
@@ -72,12 +72,12 @@ namespace Markdig.Syntax.Inlines
|
||||
/// <summary>
|
||||
/// The URL source span.
|
||||
/// </summary>
|
||||
public SourceSpan? UrlSourceSpan;
|
||||
public SourceSpan? UrlSpan;
|
||||
|
||||
/// <summary>
|
||||
/// The title source span.
|
||||
/// </summary>
|
||||
public SourceSpan? TitleSourceSpan;
|
||||
public SourceSpan? TitleSpan;
|
||||
|
||||
/// <summary>
|
||||
/// The label span
|
||||
|
||||
Reference in New Issue
Block a user