mirror of
https://github.com/xoofx/markdig.git
synced 2026-10-08 14:48:32 +00:00
Remove hardcoded attached LinkReferenceDefinitions from Document and use GetData/SetData
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Textamina.Markdig.Extensions.Footnotes
|
||||
Footnote = footnote,
|
||||
CreateLinkInline = CreateLinkToFootnote
|
||||
};
|
||||
state.Document.LinkReferenceDefinitions[footnote.Label] = linkRef;
|
||||
state.Document.GetLinkReferenceDefinitions()[footnote.Label] = linkRef;
|
||||
|
||||
state.NewBlocks.Push(footnote);
|
||||
return BlockState.Continue;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Textamina.Markdig.Parsers.Inlines
|
||||
// If the label is followed by either a ( or a [, this is not a shortcut
|
||||
if (LinkHelper.TryParseLabel(ref slice, out label))
|
||||
{
|
||||
if (!state.Document.LinkReferenceDefinitions.ContainsKey(label))
|
||||
if (!state.Document.GetLinkReferenceDefinitions().ContainsKey(label))
|
||||
{
|
||||
label = null;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace Textamina.Markdig.Parsers.Inlines
|
||||
{
|
||||
bool isValidLink = false;
|
||||
LinkReferenceDefinition linkRef;
|
||||
if (state.Document.LinkReferenceDefinitions.TryGetValue(label, out linkRef))
|
||||
if (state.Document.GetLinkReferenceDefinitions().TryGetValue(label, out linkRef))
|
||||
{
|
||||
Inline link = null;
|
||||
// Try to use a callback directly defined on the LinkReferenceDefinition
|
||||
|
||||
@@ -139,6 +139,7 @@ namespace Textamina.Markdig.Parsers
|
||||
{
|
||||
bool atLeastOneFound = false;
|
||||
|
||||
var references = state.Document.GetLinkReferenceDefinitions();
|
||||
while (true)
|
||||
{
|
||||
// If we have found a LinkReferenceDefinition, we can discard the previous paragraph
|
||||
@@ -146,9 +147,9 @@ namespace Textamina.Markdig.Parsers
|
||||
LinkReferenceDefinition linkReferenceDefinition;
|
||||
if (LinkReferenceDefinition.TryParse(ref iterator, out linkReferenceDefinition))
|
||||
{
|
||||
if (!state.Document.LinkReferenceDefinitions.ContainsKey(linkReferenceDefinition.Label))
|
||||
if (!references.ContainsKey(linkReferenceDefinition.Label))
|
||||
{
|
||||
state.Document.LinkReferenceDefinitions[linkReferenceDefinition.Label] = linkReferenceDefinition;
|
||||
references[linkReferenceDefinition.Label] = linkReferenceDefinition;
|
||||
}
|
||||
atLeastOneFound = true;
|
||||
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Textamina.Markdig.Syntax
|
||||
namespace Textamina.Markdig.Syntax
|
||||
{
|
||||
public class Document : ContainerBlock
|
||||
{
|
||||
public Document() : base(null)
|
||||
{
|
||||
LinkReferenceDefinitions = new Dictionary<string, LinkReferenceDefinition>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public Dictionary<string, LinkReferenceDefinition> LinkReferenceDefinitions { get; }
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ namespace Textamina.Markdig.Syntax
|
||||
{
|
||||
public class LinkReferenceDefinition : LeafBlock
|
||||
{
|
||||
public static readonly object DocumentKey = typeof (LinkReferenceDefinition);
|
||||
|
||||
public delegate Inline CreateLinkInlineDelegate(InlineParserState inlineState, LinkReferenceDefinition linkRef, Inline child = null);
|
||||
|
||||
public LinkReferenceDefinition() : base(null)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Textamina.Markdig.Syntax
|
||||
{
|
||||
public static class LinkReferenceDefinitionExtensions
|
||||
{
|
||||
public static Dictionary<string, LinkReferenceDefinition> GetLinkReferenceDefinitions(this Document document)
|
||||
{
|
||||
var references = document.GetData(LinkReferenceDefinition.DocumentKey) as Dictionary<string, LinkReferenceDefinition>;
|
||||
if (references == null)
|
||||
{
|
||||
references = new Dictionary<string, LinkReferenceDefinition>(StringComparer.OrdinalIgnoreCase);
|
||||
document.SetData(LinkReferenceDefinition.DocumentKey, references);
|
||||
}
|
||||
return references;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,7 @@
|
||||
<Compile Include="Parsers\BlockParserList.cs" />
|
||||
<Compile Include="Parsers\IBlockParser.cs" />
|
||||
<Compile Include="Renderers\TextRendererBase.cs" />
|
||||
<Compile Include="Syntax\LinkReferenceDefinitionExtensions.cs" />
|
||||
<Compile Include="Syntax\MarkdownObject.cs" />
|
||||
<Compile Include="Parsers\IMarkdownParser.cs" />
|
||||
<Compile Include="Parsers\IDelimiterProcessor.cs" />
|
||||
|
||||
Reference in New Issue
Block a user