diff --git a/Parsedown.php b/Parsedown.php index 447a7d0..134197b 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -417,6 +417,37 @@ class Parsedown } } + # Inline Link / Image + + if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^][]+|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline + { + foreach ($matches as $matches) + { + if ($matches[1]) # image + { + $element = ''.$matches[3].''; + } + else + { + $element_text = $this->parse_inline_elements($matches[3]); + + $element = ''.$element_text.''; + } + + $element_text = $this->parse_inline_elements($matches[1]); + + # ~ + + $code = "\x1A".'$'.$index; + + $text = str_replace($matches[0], $code, $text); + + $map[$code] = $element; + + $index ++; + } + } + # Reference(d) Link / Image if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER)) @@ -457,37 +488,6 @@ class Parsedown } } - # Inline Link / Image - - if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^][]+|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline - { - foreach ($matches as $matches) - { - if ($matches[1]) # image - { - $element = ''.$matches[3].''; - } - else - { - $element_text = $this->parse_inline_elements($matches[3]); - - $element = ''.$element_text.''; - } - - $element_text = $this->parse_inline_elements($matches[1]); - - # ~ - - $code = "\x1A".'$'.$index; - - $text = str_replace($matches[0], $code, $text); - - $map[$code] = $element; - - $index ++; - } - } - if (strpos($text, '<') !== FALSE and preg_match_all('/<((https?|ftp|dict):[^\^\s]+?)>/i', $text, $matches, PREG_SET_ORDER)) { foreach ($matches as $matches)