mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 17:30:52 +00:00
Fix LinkReferenceDefinition source positions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// This file is licensed under the BSD-Clause 2 license.
|
||||
// See the license.txt file in the project root for more information.
|
||||
using System;
|
||||
@@ -116,9 +116,16 @@ namespace Markdig
|
||||
extension.Setup(this);
|
||||
}
|
||||
|
||||
pipeline = new MarkdownPipeline(new OrderedList<IMarkdownExtension>(Extensions),
|
||||
new BlockParserList(BlockParsers), new InlineParserList(InlineParsers), StringBuilderCache, DebugLog,
|
||||
GetDocumentProcessed) {PreciseSourceLocation = PreciseSourceLocation};
|
||||
pipeline = new MarkdownPipeline(
|
||||
new OrderedList<IMarkdownExtension>(Extensions),
|
||||
new BlockParserList(BlockParsers),
|
||||
new InlineParserList(InlineParsers),
|
||||
StringBuilderCache,
|
||||
DebugLog,
|
||||
GetDocumentProcessed)
|
||||
{
|
||||
PreciseSourceLocation = PreciseSourceLocation
|
||||
};
|
||||
return pipeline;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// 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;
|
||||
@@ -9,7 +9,7 @@ namespace Markdig.Parsers
|
||||
/// <summary>
|
||||
/// Block parser for a <see cref="ParagraphBlock"/>.
|
||||
/// </summary>
|
||||
/// <seealso cref="Markdig.Parsers.BlockParser" />
|
||||
/// <seealso cref="BlockParser" />
|
||||
public class ParagraphBlockParser : BlockParser
|
||||
{
|
||||
public override BlockState TryOpen(BlockProcessor processor)
|
||||
@@ -152,15 +152,20 @@ namespace Markdig.Parsers
|
||||
{
|
||||
// If we have found a LinkReferenceDefinition, we can discard the previous paragraph
|
||||
var iterator = lines.ToCharIterator();
|
||||
LinkReferenceDefinition linkReferenceDefinition;
|
||||
if (LinkReferenceDefinition.TryParse(ref iterator, out linkReferenceDefinition))
|
||||
{
|
||||
if (!state.Document.ContainsLinkReferenceDefinition(linkReferenceDefinition.Label))
|
||||
{
|
||||
state.Document.SetLinkReferenceDefinition(linkReferenceDefinition.Label, linkReferenceDefinition);
|
||||
}
|
||||
if (LinkReferenceDefinition.TryParse(ref iterator, out LinkReferenceDefinition linkReferenceDefinition))
|
||||
{
|
||||
state.Document.SetLinkReferenceDefinition(linkReferenceDefinition.Label, linkReferenceDefinition);
|
||||
atLeastOneFound = true;
|
||||
|
||||
// Correct the locations of each field
|
||||
linkReferenceDefinition.Line = lines.Lines[0].Line;
|
||||
int lineStartPosition = lines.Lines[0].Position + 1;
|
||||
|
||||
linkReferenceDefinition.Span = linkReferenceDefinition.Span .MoveForward(lineStartPosition);
|
||||
linkReferenceDefinition.LabelSpan = linkReferenceDefinition.LabelSpan .MoveForward(lineStartPosition);
|
||||
linkReferenceDefinition.UrlSpan = linkReferenceDefinition.UrlSpan .MoveForward(lineStartPosition);
|
||||
linkReferenceDefinition.TitleSpan = linkReferenceDefinition.TitleSpan .MoveForward(lineStartPosition);
|
||||
|
||||
// Remove lines that have been matched
|
||||
if (iterator.Start > iterator.End)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// This file is licensed under the BSD-Clause 2 license.
|
||||
// See the license.txt file in the project root for more information.
|
||||
|
||||
@@ -28,11 +28,14 @@ namespace Markdig.Syntax
|
||||
|
||||
public void Set(string label, LinkReferenceDefinition link)
|
||||
{
|
||||
if (link == null) throw new ArgumentNullException(nameof(link));
|
||||
Links[label] = link;
|
||||
if (!Contains(link))
|
||||
{
|
||||
Add(link);
|
||||
if (link == null) throw new ArgumentNullException(nameof(link));
|
||||
if (!Contains(link))
|
||||
{
|
||||
Add(link);
|
||||
if (!Links.ContainsKey(label))
|
||||
{
|
||||
Links[label] = link;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// This file is licensed under the BSD-Clause 2 license.
|
||||
// See the license.txt file in the project root for more information.
|
||||
|
||||
@@ -43,6 +43,11 @@ namespace Markdig.Syntax
|
||||
|
||||
public bool IsEmpty => Start > End;
|
||||
|
||||
public SourceSpan MoveForward(int count)
|
||||
{
|
||||
return new SourceSpan(Start + count, End + count);
|
||||
}
|
||||
|
||||
public bool Equals(SourceSpan other)
|
||||
{
|
||||
return Start == other.Start && End == other.End;
|
||||
|
||||
Reference in New Issue
Block a user