mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
parse link references as blocks to improve performance
This commit is contained in:
parent
6d113f47fb
commit
b12973415f
@ -75,18 +75,6 @@ class Parsedown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Extracts link references.
|
|
||||||
|
|
||||||
if (preg_match_all('/^[ ]{0,3}\[(.+)\][ ]?:[ ]*\n?[ ]*(.+)$/m', $text, $matches, PREG_SET_ORDER))
|
|
||||||
{
|
|
||||||
foreach ($matches as $matches)
|
|
||||||
{
|
|
||||||
$this->reference_map[strtolower($matches[1])] = $matches[2];
|
|
||||||
|
|
||||||
$text = str_replace($matches[0], '', $text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# ~
|
# ~
|
||||||
|
|
||||||
$text = preg_replace('/\n\s*\n/', "\n\n", $text);
|
$text = preg_replace('/\n\s*\n/', "\n\n", $text);
|
||||||
@ -217,7 +205,7 @@ class Parsedown
|
|||||||
|
|
||||||
# Quick Paragraph
|
# Quick Paragraph
|
||||||
|
|
||||||
if ($line[0] >= 'A' and $line[0] !== '_')
|
if ($line[0] >= 'A' and $line[0] !== '_' and $line[0] !== '[')
|
||||||
{
|
{
|
||||||
goto paragraph; # trust me
|
goto paragraph; # trust me
|
||||||
}
|
}
|
||||||
@ -286,6 +274,18 @@ class Parsedown
|
|||||||
|
|
||||||
$pure_line = ltrim($line);
|
$pure_line = ltrim($line);
|
||||||
|
|
||||||
|
# Link Reference
|
||||||
|
|
||||||
|
if ($pure_line[0] === '[' and preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $pure_line, $matches))
|
||||||
|
{
|
||||||
|
$label = $matches[1];
|
||||||
|
$url = trim($matches[2], '<>');
|
||||||
|
|
||||||
|
$this->reference_map[$label] = $url;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
# Blockquote
|
# Blockquote
|
||||||
|
|
||||||
if ($pure_line[0] === '>' and preg_match('/^>[ ]?(.*)/', $pure_line, $matches))
|
if ($pure_line[0] === '>' and preg_match('/^>[ ]?(.*)/', $pure_line, $matches))
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
<p>Here's a <a href="http://parsedown.org">reference link</a>.</p>
|
<p>Here's a <a href="http://parsedown.org">reference link</a>.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> with an alternative syntax.</p>
|
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> on the next line.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> on the next line.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> on 2 lines.</p>
|
|
||||||
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
<p>Here's <a href="http://parsedown.org/tests/">one</a> with a different URL.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> with a semantic name.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> with a semantic name.</p>
|
||||||
<p>Here's <a href="http://parsedown.org">one</a> with definition name on the next line.</p>
|
<p>Here's <a href="http://parsedown.org">one</a> with definition name on the next line.</p>
|
||||||
<p>Here's [one][404] with no definition.</p>
|
<p>Here's [one][404] with no definition.</p>
|
||||||
<p>Here's an image: <img alt="Markdown Logo" src="/md.png"></p>
|
<p>Here's an image: <img alt="Markdown Logo" src="/md.png"></p>
|
||||||
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
||||||
<p>Here's an <a href="http://google.com">implicit one</a>.</p>
|
|
||||||
<p>Here's an <a href="http://google.com">implicit one</a> with an empty link definition.</p>
|
<p>Here's an <a href="http://google.com">implicit one</a> with an empty link definition.</p>
|
||||||
<p>Here's a <a href="http://parsedown.org">multiline
|
<p>Here's a <a href="http://parsedown.org">multiline
|
||||||
one</a> defined on 2 lines.</p>
|
one</a> defined on 2 lines.</p>
|
@ -2,21 +2,12 @@ Here's a [reference link][1].
|
|||||||
|
|
||||||
[1]: http://parsedown.org
|
[1]: http://parsedown.org
|
||||||
|
|
||||||
Here's [one] [2] with an alternative syntax.
|
Here's [one][2] on the next line.
|
||||||
|
[2]: http://parsedown.org
|
||||||
|
|
||||||
[2] :http://parsedown.org
|
Here's [one][3] with a different URL.
|
||||||
|
|
||||||
Here's [one][3] on the next line.
|
[3]: http://parsedown.org/tests/
|
||||||
[3]: http://parsedown.org
|
|
||||||
|
|
||||||
Here's [one][4] on 2 lines.
|
|
||||||
|
|
||||||
[4]:
|
|
||||||
http://parsedown.org
|
|
||||||
|
|
||||||
Here's [one][5] with a different URL.
|
|
||||||
|
|
||||||
[5]: http://parsedown.org/tests/
|
|
||||||
|
|
||||||
Here's [one][website] with a semantic name.
|
Here's [one][website] with a semantic name.
|
||||||
|
|
||||||
@ -33,8 +24,6 @@ Here's an image: ![Markdown Logo][image]
|
|||||||
|
|
||||||
Here's an [implicit one].
|
Here's an [implicit one].
|
||||||
|
|
||||||
Here's an [implicit one].
|
|
||||||
|
|
||||||
[implicit one]: http://google.com
|
[implicit one]: http://google.com
|
||||||
|
|
||||||
Here's an [implicit one][] with an empty link definition.
|
Here's an [implicit one][] with an empty link definition.
|
||||||
|
Loading…
Reference in New Issue
Block a user