Fix heading auto-link hijacking nested link labels (#668) (#949)

* Fix heading auto-link hijacking nested link labels (#668)

* Refactor heading reference resolution to init-only state (#949)

---------

Co-authored-by: Alexandre Mutel <alexandre_mutel@live.com>
This commit is contained in:
dualfrozandAlexandre Mutel committed 2026-09-19 11:41:48 +02:00
1 parent 40eebc0cd8
commit 9006f0b4a2
6 files changed
+114 -1

No files matched your search

@@ -150,6 +150,13 @@ public class LinkInlineParser : InlineParser
return false;
}
// An implicit definition must not hijack a bracket nested inside a
// still-open link, which would break the outer one.
if (!linkRef.AllowResolutionInsideOpenLink && HasActiveAncestorLink(parent))
{
return false;
}
Inline? link = null;
// Try to use a callback directly defined on the LinkReferenceDefinition
if (linkRef.CreateLinkInline != null)
@@ -430,6 +437,24 @@ public class LinkInlineParser : InlineParser
}
}
/// <summary>
/// Determines whether the delimiter is nested inside another link/image
/// delimiter that may still resolve.
/// </summary>
private static bool HasActiveAncestorLink(LinkDelimiterInline delimiter)
{
var inline = delimiter.Parent;
while (inline != null)
{
if (inline is LinkDelimiterInline { IsActive: true })
{
return true;
}
inline = inline.Parent;
}
return false;
}
private static void MarkParentAsInactive(Inline? inline)
{
while (inline != null)