Browse Source

Markdown.pl: be careful with bold/italic/strikethrough in anchor text

This, for example:

    [Looking at a*](#something) is *good*

Must not produce this broken output:

    <a href="#something">Looking at a<em></a> is *good</em>

But instead this:

    <a href="#something">Looking at a*</a> is <em>good</em>

Achieve this by making a special pass to handle bold, italic and
strikethrough on the anchor text and then "hiding" any remaining
markup characters that might be confusingly matched up with characters
outside the anchor text.

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

4
Markdown.pl

@ -1001,6 +1001,10 @@ sub _MakeATag {
my $result = $g_escape_table{'<'}."a href=\"" . _EncodeAttText($url) . "\"";
$title = _strip($title);
$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;
$result .= " title=\"" . _EncodeAttText($title) . "\"" if $title ne "";
return $result . $g_escape_table{'>'} .
$text . $g_escape_table{'<'}."/a".$g_escape_table{'>'};

Loading…
Cancel
Save