parse code span after recursive types to resolve #44
This commit is contained in:
parent
22336a1bcc
commit
85ad014f74
|
@ -629,38 +629,7 @@ class Parsedown
|
||||||
|
|
||||||
$index = 0;
|
$index = 0;
|
||||||
|
|
||||||
# code span
|
# inline link or image (recursive)
|
||||||
|
|
||||||
if (strpos($text, '`') !== FALSE and preg_match_all('/`(.+?)`/', $text, $matches, PREG_SET_ORDER))
|
|
||||||
{
|
|
||||||
foreach ($matches as $matches)
|
|
||||||
{
|
|
||||||
$element_text = $matches[1];
|
|
||||||
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
|
||||||
|
|
||||||
# decodes escape sequences
|
|
||||||
|
|
||||||
$this->escape_sequence_map
|
|
||||||
and strpos($element_text, "\x1A") !== FALSE
|
|
||||||
and $element_text = strtr($element_text, $this->escape_sequence_map);
|
|
||||||
|
|
||||||
# composes element
|
|
||||||
|
|
||||||
$element = '<code>'.$element_text.'</code>';
|
|
||||||
|
|
||||||
# encodes element
|
|
||||||
|
|
||||||
$code = "\x1A".'$'.$index;
|
|
||||||
|
|
||||||
$text = str_replace($matches[0], $code, $text);
|
|
||||||
|
|
||||||
$map[$code] = $element;
|
|
||||||
|
|
||||||
$index ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# inline link or image
|
|
||||||
|
|
||||||
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
|
if (strpos($text, '](') !== FALSE and preg_match_all('/(!?)(\[((?:[^\[\]]|(?2))*)\])\((.*?)\)/', $text, $matches, PREG_SET_ORDER)) # inline
|
||||||
{
|
{
|
||||||
|
@ -693,7 +662,7 @@ class Parsedown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# reference link or image
|
# reference link or image (recursive)
|
||||||
|
|
||||||
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
|
if ($this->reference_map and strpos($text, '[') !== FALSE and preg_match_all('/(!?)\[(.+?)\](?:\n?[ ]?\[(.*?)\])?/ms', $text, $matches, PREG_SET_ORDER))
|
||||||
{
|
{
|
||||||
|
@ -735,6 +704,37 @@ class Parsedown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# code span
|
||||||
|
|
||||||
|
if (strpos($text, '`') !== FALSE and preg_match_all('/`(.+?)`/', $text, $matches, PREG_SET_ORDER))
|
||||||
|
{
|
||||||
|
foreach ($matches as $matches)
|
||||||
|
{
|
||||||
|
$element_text = $matches[1];
|
||||||
|
$element_text = htmlspecialchars($element_text, ENT_NOQUOTES, 'UTF-8');
|
||||||
|
|
||||||
|
# decodes escape sequences
|
||||||
|
|
||||||
|
$this->escape_sequence_map
|
||||||
|
and strpos($element_text, "\x1A") !== FALSE
|
||||||
|
and $element_text = strtr($element_text, $this->escape_sequence_map);
|
||||||
|
|
||||||
|
# composes element
|
||||||
|
|
||||||
|
$element = '<code>'.$element_text.'</code>';
|
||||||
|
|
||||||
|
# encodes element
|
||||||
|
|
||||||
|
$code = "\x1A".'$'.$index;
|
||||||
|
|
||||||
|
$text = str_replace($matches[0], $code, $text);
|
||||||
|
|
||||||
|
$map[$code] = $element;
|
||||||
|
|
||||||
|
$index ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# automatic link
|
# automatic link
|
||||||
|
|
||||||
if (strpos($text, '://') !== FALSE)
|
if (strpos($text, '://') !== FALSE)
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
<p><a href="http://example.com">link</a></p>
|
<p><a href="http://example.com">link</a></p>
|
||||||
|
<p><a href="http://example.com"><code>link</code></a></p>
|
||||||
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png"></a></p>
|
<p><a href="http://example.com"><img alt="MD Logo" src="http://parsedown.org/md.png"></a></p>
|
|
@ -1,3 +1,5 @@
|
||||||
[link](http://example.com)
|
[link](http://example.com)
|
||||||
|
|
||||||
|
[`link`](http://example.com)
|
||||||
|
|
||||||
[![MD Logo](http://parsedown.org/md.png)](http://example.com)
|
[![MD Logo](http://parsedown.org/md.png)](http://example.com)
|
|
@ -4,3 +4,4 @@
|
||||||
<p><a href="http://example.com">multiline
|
<p><a href="http://example.com">multiline
|
||||||
one</a> defined on 2 lines</p>
|
one</a> defined on 2 lines</p>
|
||||||
<p><a href="http://example.com">one</a> with an upper case label</p>
|
<p><a href="http://example.com">one</a> with an upper case label</p>
|
||||||
|
<p><a href="http://example.com"><code>link</code></a></p>
|
|
@ -14,3 +14,5 @@ one][website] defined on 2 lines
|
||||||
[one][label] with an upper case label
|
[one][label] with an upper case label
|
||||||
|
|
||||||
[LABEL]: http://example.com
|
[LABEL]: http://example.com
|
||||||
|
|
||||||
|
[`link`][website]
|
Loading…
Reference in New Issue