From ea408f7d29df17eda2cda748960efde855ef90ae Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 8 Jul 2020 03:21:14 -0700 Subject: [PATCH] Markdown.pl: hook up fragment only link definitions This works to hook up a fragment link to its section: # Section 1 Link to [Top](#Section_1). Make the same thing work when written like this: # Section 1 Link to [Top][id]. [id]: #Section_1 Or even like this: # Section 1 Link to [id]. [id]: #Section_1 Signed-off-by: Kyle J. McKay --- Markdown.pl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Markdown.pl b/Markdown.pl index 45cb887..4241c1e 100755 --- a/Markdown.pl +++ b/Markdown.pl @@ -1120,9 +1120,10 @@ sub _DoAnchors { if (defined($g_urls{$link_id}) || defined($g_anchors{$link_id})) { my $url = $g_urls{$link_id}; - $url = defined($url) ? _PrefixURL($url) : $g_anchors{$link_id}; + defined($url) or $url = $g_anchors{$link_id}; + $url = _FindFragmentMatch($url); $link_text = '[' . $link_text . ']' if $link_text =~ /^\d{1,3}$/; - $result = _MakeATag($url, $link_text, $g_titles{$link_id}); + $result = _MakeATag(_PrefixURL($url), $link_text, $g_titles{$link_id}); } else { $result = $whole_match; @@ -1175,9 +1176,10 @@ sub _DoAnchors { if (defined($g_urls{$link_id}) || defined($g_anchors{$link_id})) { my $url = $g_urls{$link_id}; - $url = defined($url) ? _PrefixURL($url) : $g_anchors{$link_id}; + defined($url) or $url = $g_anchors{$link_id}; + $url = _FindFragmentMatch($url); $link_text = '[' . $link_text . ']' if $link_text =~ /^\d{1,3}$/; - $result = _MakeATag($url, $link_text, $g_titles{$link_id}); + $result = _MakeATag(_PrefixURL($url), $link_text, $g_titles{$link_id}); } else { $result = $whole_match;