1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Merge pull request #114 from wkpark/fixup_reference_label

fixup internal reference labling to make code more readable
This commit is contained in:
Emanuil Rusev 2014-02-20 13:41:18 +02:00
commit 7a20a9fb60

View File

@ -459,7 +459,7 @@ class Parsedown
break; break;
} }
$reference['»'] = substr($substring, 1, $position - 1); $reference['link'] = substr($substring, 1, $position - 1);
$substring = substr($substring, $position + 1); $substring = substr($substring, $position + 1);
} }
@ -469,13 +469,13 @@ class Parsedown
if ($position === false) if ($position === false)
{ {
$reference['»'] = $substring; $reference['link'] = $substring;
$substring = false; $substring = false;
} }
else else
{ {
$reference['»'] = substr($substring, 0, $position); $reference['link'] = substr($substring, 0, $position);
$substring = substr($substring, $position + 1); $substring = substr($substring, $position + 1);
} }
@ -495,7 +495,7 @@ class Parsedown
break; break;
} }
$reference['#'] = substr($substring, 1, -1); $reference['title'] = substr($substring, 1, -1);
} }
$this->reference_map[$label] = $reference; $this->reference_map[$label] = $reference;
@ -829,7 +829,7 @@ class Parsedown
{ {
$element = array( $element = array(
'!' => $text[0] === '!', '!' => $text[0] === '!',
'a' => $matches[1], 'text' => $matches[1],
); );
$offset = strlen($matches[0]); $offset = strlen($matches[0]);
@ -843,22 +843,22 @@ class Parsedown
if ($remaining_text[0] === '(' and preg_match('/\([ ]*(.*?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*\)/', $remaining_text, $matches)) if ($remaining_text[0] === '(' and preg_match('/\([ ]*(.*?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*\)/', $remaining_text, $matches))
{ {
$element['»'] = $matches[1]; $element['link'] = $matches[1];
if (isset($matches[2])) if (isset($matches[2]))
{ {
$element['#'] = $matches[2]; $element['title'] = $matches[2];
} }
$offset += strlen($matches[0]); $offset += strlen($matches[0]);
} }
elseif ($this->reference_map) elseif ($this->reference_map)
{ {
$reference = $element['a']; $reference = $element['text'];
if (preg_match('/^\s*\[(.*?)\]/', $remaining_text, $matches)) if (preg_match('/^\s*\[(.*?)\]/', $remaining_text, $matches))
{ {
$reference = $matches[1] ? $matches[1] : $element['a']; $reference = $matches[1] ? $matches[1] : $element['text'];
$offset += strlen($matches[0]); $offset += strlen($matches[0]);
} }
@ -867,11 +867,11 @@ class Parsedown
if (isset($this->reference_map[$reference])) if (isset($this->reference_map[$reference]))
{ {
$element['»'] = $this->reference_map[$reference]['»']; $element['link'] = $this->reference_map[$reference]['link'];
if (isset($this->reference_map[$reference]['#'])) if (isset($this->reference_map[$reference]['title']))
{ {
$element['#'] = $this->reference_map[$reference]['#']; $element['title'] = $this->reference_map[$reference]['title'];
} }
} }
else else
@ -887,32 +887,32 @@ class Parsedown
if (isset($element)) if (isset($element))
{ {
$element['»'] = str_replace('&', '&', $element['»']); $element['link'] = str_replace('&', '&', $element['link']);
$element['»'] = str_replace('<', '&lt;', $element['»']); $element['link'] = str_replace('<', '&lt;', $element['link']);
if ($element['!']) if ($element['!'])
{ {
$markup .= '<img alt="'.$element['a'].'" src="'.$element['].'"'; $markup .= '<img alt="'.$element['text'].'" src="'.$element['link'].'"';
if (isset($element['#'])) if (isset($element['title']))
{ {
$markup .= ' title="'.$element['#'].'"'; $markup .= ' title="'.$element['title'].'"';
} }
$markup .= ' />'; $markup .= ' />';
} }
else else
{ {
$element['a'] = $this->parse_span_elements($element['a'], $markers); $element['text'] = $this->parse_span_elements($element['text'], $markers);
$markup .= '<a href="'.$element['»'].'"'; $markup .= '<a href="'.$element['link'].'"';
if (isset($element['#'])) if (isset($element['title']))
{ {
$markup .= ' title="'.$element['#'].'"'; $markup .= ' title="'.$element['title'].'"';
} }
$markup .= '>'.$element['a'].'</a>'; $markup .= '>'.$element['text'].'</a>';
} }
unset($element); unset($element);