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:
@@ -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);
|
||||
@@ -217,7 +205,7 @@ class Parsedown
|
||||
|
||||
# Quick Paragraph
|
||||
|
||||
if ($line[0] >= 'A' and $line[0] !== '_')
|
||||
if ($line[0] >= 'A' and $line[0] !== '_' and $line[0] !== '[')
|
||||
{
|
||||
goto paragraph; # trust me
|
||||
}
|
||||
@@ -282,10 +270,22 @@ class Parsedown
|
||||
continue;
|
||||
}
|
||||
|
||||
# ~
|
||||
# ~
|
||||
|
||||
$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
|
||||
|
||||
if ($pure_line[0] === '>' and preg_match('/^>[ ]?(.*)/', $pure_line, $matches))
|
||||
|
Reference in New Issue
Block a user