resolve #88, resolve #81

This commit is contained in:
Emanuil Rusev 2014-02-05 14:03:23 +02:00
parent 548a6f7945
commit ba7f377290
1 changed files with 58 additions and 7 deletions

View File

@ -426,18 +426,69 @@ class Parsedown
# reference # reference
if (preg_match('/^\[(.+?)\]:[ ]*(.+?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*$/', $outdented_line, $matches)) $position = strpos($outdented_line, ']:');
if ($position)
{ {
$label = strtolower($matches[1]); $reference = array();
$this->reference_map[$label] = array( $label = substr($outdented_line, 1, $position - 1);
'»' => trim($matches[2], '<>'),
);
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; continue 2;
} }