Browse Source

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 <mackyle@gmail.com>
master
Kyle J. McKay 4 years ago
parent
commit
ea408f7d29
  1. 10
      Markdown.pl

10
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;

Loading…
Cancel
Save