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

This commit is contained in:
dualfroz committed 2026-09-06 01:19:53 +02:00
1 parent 93406f115e
commit ad32938cc0
4 files changed
+66

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)