Browse Source

Markdown.pl: avoid accidentally nested anchors

Given something that looks like this:

        [1][]
        [1]: https://example.com/

Ever since commit dfbf2b4e30
("Markdown.pl: retain square brackets around footnotes", 2017-01-19,
markdown_1.1.2), the link text has been rendered to include the
surrounding '[' and ']' because it just looks better that way and
produces a bigger link target.

Unfortunately that can result in the linked text being processed
again and producing a nexted anchor which is not only invalid
according to the XHTML specification but is also the wrong rendering
for the input.

Deal with this by hiding the '[' and ']' characters inside link
text the same way other characters within the link text are already
being hidden.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
master
Kyle J. McKay 3 years ago
parent
commit
ff7fb525fc
  1. 4
      Markdown.pl

4
Markdown.pl

@ -1583,8 +1583,8 @@ sub _MakeATag {
$text =~ s{<(/?a)}{&lt;$1}sogi;
$text = _DoItalicsAndBoldAndStrike($text);
# We've got to encode any of these remaining to avoid
# conflicting with other italics, bold and strike through.
$text =~ s!([*_~])!$g_escape_table{$1}!g;
# conflicting with other italics, bold and strike through and links.
$text =~ s!([]*_~[])!$g_escape_table{$1}!g;
$result .= " title=\"" . _EncodeAttText($title) . "\"" if $title ne "";
return $result . $g_escape_table{'>'} .
$text . $g_escape_table{'<'}."/a".$g_escape_table{'>'};

Loading…
Cancel
Save