Browse Source

Markdown.pl: use g_nested_brackets for images too

The recursive regex `$g_nested_brackets` (see the source) correctly
matches properly balanced nested `[`...`]` text.

The normal anchor parsing already makes use of it.

Use it for the image parsing too so that this:

    [![Alt](img.png)][link]
    [link]:example.txt

Does not become the very broken:

    <a href="img.png"><img src="example.txt" alt="Alt</a>" />

But instead becomes the correct:

    <a href="example.txt"><img src="img.png" alt="Alt" /></a>

This problem has been present all the way back to Markdown.pl version
1.0.1 (2004-12-14) and likely earlier too.

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

6
Markdown.pl

@ -1207,7 +1207,7 @@ sub _DoImages {
$text =~ s{
( # wrap whole match in $1
!\[
(.*?) # alt text = $2
($g_nested_brackets) # alt text = $2
\]
[ ]? # one optional space
@ -1246,7 +1246,7 @@ sub _DoImages {
$text =~ s{
( # wrap whole match in $1
!\[
(.*?) # alt text = $2
($g_nested_brackets) # alt text = $2
\]
\( # literal paren
[ ]*
@ -1278,7 +1278,7 @@ sub _DoImages {
$text =~ s{
( # wrap whole match in $1
!\[
(.*?) # alt text = $2
($g_nested_brackets) # alt text = $2
\]
)
}{

Loading…
Cancel
Save