mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
parent
548a6f7945
commit
ba7f377290
@ -426,18 +426,69 @@ class Parsedown
|
||||
|
||||
# reference
|
||||
|
||||
if (preg_match('/^\[(.+?)\]:[ ]*(.+?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*$/', $outdented_line, $matches))
|
||||
$position = strpos($outdented_line, ']:');
|
||||
|
||||
if ($position)
|
||||
{
|
||||
$label = strtolower($matches[1]);
|
||||
$reference = array();
|
||||
|
||||
$this->reference_map[$label] = array(
|
||||
'»' => trim($matches[2], '<>'),
|
||||
);
|
||||
$label = substr($outdented_line, 1, $position - 1);
|
||||
|
||||
if (isset($matches[3]))
|
||||
$substring = substr($outdented_line, $position + 2);
|
||||
$substring = trim($substring);
|
||||
|
||||
if ($substring[0] === '<')
|
||||
{
|
||||
$this->reference_map[$label]['#'] = $matches[3];
|
||||
$position = strpos($substring, '>');
|
||||
|
||||
if ($position === false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$reference['»'] = substr($substring, 1, $position - 1);
|
||||
|
||||
$substring = substr($substring, $position + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$position = strpos($substring, ' ');
|
||||
|
||||
if ($position === false)
|
||||
{
|
||||
$reference['»'] = $substring;
|
||||
|
||||
$substring = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$reference['»'] = substr($substring, 0, $position);
|
||||
|
||||
$substring = substr($substring, $position + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($substring !== false)
|
||||
{
|
||||
$last_char = substr($substring, -1);
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case $substring[0] === '"' and $substring[0] === $last_char:
|
||||
case $substring[0] === "'" and $substring[0] === $last_char:
|
||||
case $substring[0] === '(' and $last_char === ')':
|
||||
|
||||
$reference['#'] = substr($substring, 1, -1);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
$this->reference_map[$label] = $reference;
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user