mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
separate compiling of link / image
there are 2 types of input that produce link / image
This commit is contained in:
parent
4fecd91f7d
commit
68484504ca
@ -723,40 +723,30 @@ class Parsedown
|
||||
|
||||
if (strpos($text, ']') and preg_match('/\[((?:[^][]|(?R))*)\]/', $text, $matches))
|
||||
{
|
||||
$brackets_text = $matches[1];
|
||||
$element = array(
|
||||
'!' => $text[0] === '!',
|
||||
'a' => $matches[1],
|
||||
);
|
||||
|
||||
$offset = strlen($matches[0]);
|
||||
|
||||
$element_is_image = $text[0] === '!' and $offset++;
|
||||
$element['!'] and $offset++;
|
||||
|
||||
$remaining_text = substr($text, $offset);
|
||||
|
||||
if ($remaining_text[0] === '(' and preg_match('/^\((.*?)\)/', $remaining_text, $matches))
|
||||
{
|
||||
$element_url = $matches[1];
|
||||
$element_url = str_replace('&', '&', $element_url);
|
||||
$element_url = str_replace('<', '<', $element_url);
|
||||
|
||||
if ($element_is_image)
|
||||
{
|
||||
$markup .= '<img alt="'.$brackets_text.'" src="'.$element_url.'" />';
|
||||
}
|
||||
else
|
||||
{
|
||||
$element_text = $this->parse_span_elements($brackets_text, $markers);
|
||||
|
||||
$markup .= '<a href="'.$element_url.'">'.$element_text.'</a>';
|
||||
}
|
||||
$element['»'] = $matches[1];
|
||||
|
||||
$offset += strlen($matches[0]);
|
||||
}
|
||||
elseif ($this->reference_map)
|
||||
{
|
||||
$reference = $brackets_text;
|
||||
$reference = $element['a'];
|
||||
|
||||
if (preg_match('/^\s*\[(.*?)\]/', $remaining_text, $matches))
|
||||
{
|
||||
$reference = $matches[1] ? $matches[1] : $brackets_text;
|
||||
$reference = $matches[1] ? $matches[1] : $element['a'];
|
||||
|
||||
$offset += strlen($matches[0]);
|
||||
}
|
||||
@ -765,35 +755,36 @@ class Parsedown
|
||||
|
||||
if (isset($this->reference_map[$reference]))
|
||||
{
|
||||
$element_url = $this->reference_map[$reference];
|
||||
|
||||
$element_url = str_replace('&', '&', $element_url);
|
||||
$element_url = str_replace('<', '<', $element_url);
|
||||
|
||||
if ($element_is_image)
|
||||
{
|
||||
$markup .= '<img alt="'.$brackets_text.'" src="'.$element_url.'" />';
|
||||
$element['»'] = $this->reference_map[$reference];
|
||||
}
|
||||
else
|
||||
{
|
||||
$element_text = $this->parse_span_elements($brackets_text, $markers);
|
||||
|
||||
$markup .= '<a href="'.$element_url.'">'.$element_text.'</a>';
|
||||
unset($element);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$markup .= $closest_marker;
|
||||
|
||||
$offset = $element_is_image ? 2 : 1;
|
||||
unset($element);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($element))
|
||||
{
|
||||
$element['»'] = str_replace('&', '&', $element['»']);
|
||||
$element['»'] = str_replace('<', '<', $element['»']);
|
||||
|
||||
if ($element['!'])
|
||||
{
|
||||
$markup .= '<img alt="'.$element['a'].'" src="'.$element['»'].'" />';
|
||||
}
|
||||
else
|
||||
{
|
||||
$markup .= $closest_marker;
|
||||
$element['a'] = $this->parse_span_elements($element['a'], $markers);
|
||||
|
||||
$offset = $closest_marker === '![' ? 2 : 1;
|
||||
$markup .= '<a href="'.$element['»'].'">'.$element['a'].'</a>';
|
||||
}
|
||||
|
||||
unset($element);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user