mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
inline links should get parsed before reference links
This commit is contained in:
parent
f40dbdfb65
commit
64f82e1e2a
@ -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 = '<img alt="'.$matches[3].'" src="'.$matches[4].'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
$element_text = $this->parse_inline_elements($matches[3]);
|
||||
|
||||
$element = '<a href="'.$matches[4].'">'.$element_text.'</a>';
|
||||
}
|
||||
|
||||
$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 = '<img alt="'.$matches[3].'" src="'.$matches[4].'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
$element_text = $this->parse_inline_elements($matches[3]);
|
||||
|
||||
$element = '<a href="'.$matches[4].'">'.$element_text.'</a>';
|
||||
}
|
||||
|
||||
$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)
|
||||
|
Loading…
Reference in New Issue
Block a user