|
|
@@ -1,6 +1,6 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
class freaParsedown extends Parsedown { |
|
|
|
class freaParsedown extends ParsedownExtra { |
|
|
|
|
|
|
|
function get_BlockTypes() { |
|
|
|
|
|
|
@@ -55,163 +55,49 @@ class freaParsedown extends Parsedown { |
|
|
|
|
|
|
|
protected function inlineEmailTag($Excerpt) |
|
|
|
{ |
|
|
|
$hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'; |
|
|
|
|
|
|
|
$commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@' |
|
|
|
. $hostnameLabel . '(?:\.' . $hostnameLabel . ')*'; |
|
|
|
|
|
|
|
if (strpos($Excerpt['text'], '>') !== false |
|
|
|
and preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt['text'], $matches) |
|
|
|
){ |
|
|
|
$url = $matches[1]; |
|
|
|
|
|
|
|
if ( ! isset($matches[2])) |
|
|
|
{ |
|
|
|
$url = 'mailto:' . $url; |
|
|
|
} |
|
|
|
|
|
|
|
return array( |
|
|
|
'extent' => strlen($matches[0]), |
|
|
|
'element' => array( |
|
|
|
'name' => 'a', |
|
|
|
'text' => $matches[1], |
|
|
|
'attributes' => array( |
|
|
|
'href' => $url, |
|
|
|
'data-link-text' => $matches[1], |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
$Link = parent::inlineEmailTag($Excerpt); |
|
|
|
|
|
|
|
if (isset($Link)) { |
|
|
|
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']]; |
|
|
|
} |
|
|
|
return $Link; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected function inlineLink($Excerpt) |
|
|
|
{ |
|
|
|
$Element = array( |
|
|
|
'name' => 'a', |
|
|
|
'handler' => 'line', |
|
|
|
'nonNestables' => array('Url', 'Link'), |
|
|
|
'text' => null, |
|
|
|
'attributes' => array( |
|
|
|
'href' => null, |
|
|
|
'title' => null, |
|
|
|
), |
|
|
|
); |
|
|
|
|
|
|
|
$extent = 0; |
|
|
|
|
|
|
|
$remainder = $Excerpt['text']; |
|
|
|
|
|
|
|
if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) |
|
|
|
{ |
|
|
|
$Element['text'] = $matches[1]; |
|
|
|
|
|
|
|
$extent += strlen($matches[0]); |
|
|
|
|
|
|
|
$remainder = substr($remainder, $extent); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) |
|
|
|
{ |
|
|
|
$Element['attributes']['href'] = $matches[1]; |
|
|
|
|
|
|
|
if (isset($matches[2])) |
|
|
|
{ |
|
|
|
$Element['attributes']['title'] = substr($matches[2], 1, - 1); |
|
|
|
} |
|
|
|
|
|
|
|
$extent += strlen($matches[0]); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) |
|
|
|
{ |
|
|
|
$definition = strlen($matches[1]) ? $matches[1] : $Element['text']; |
|
|
|
$definition = strtolower($definition); |
|
|
|
|
|
|
|
$extent += strlen($matches[0]); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
$definition = strtolower($Element['text']); |
|
|
|
} |
|
|
|
|
|
|
|
if ( ! isset($this->DefinitionData['Reference'][$definition])) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
$Definition = $this->DefinitionData['Reference'][$definition]; |
|
|
|
|
|
|
|
$Element['attributes']['href'] = $Definition['url']; |
|
|
|
$Element['attributes']['title'] = $Definition['title']; |
|
|
|
} |
|
|
|
$Link = parent::inlineLink($Excerpt); |
|
|
|
|
|
|
|
$Element['attributes']['data-link-text'] = $Element['text']; |
|
|
|
$url=&$Element['attributes']['href']; |
|
|
|
if (strpos($url,':') === FALSE) { |
|
|
|
$url = $this->add_language_to_link_target($url); |
|
|
|
if (isset($Link)) { |
|
|
|
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']]; |
|
|
|
$url=&$Link['element']['attributes']['href']; |
|
|
|
if (strpos($url,':') === FALSE) { |
|
|
|
$url = $this->add_language_to_link_target($url); |
|
|
|
} |
|
|
|
$Link['extent'] = $Link['extent']; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return array( |
|
|
|
'extent' => $extent, |
|
|
|
'element' => $Element, |
|
|
|
); |
|
|
|
return $Link; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function inlineUrl($Excerpt) |
|
|
|
{ |
|
|
|
if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) |
|
|
|
{ |
|
|
|
$url = $matches[0][0]; |
|
|
|
|
|
|
|
$Inline = array( |
|
|
|
'extent' => strlen($matches[0][0]), |
|
|
|
'position' => $matches[0][1], |
|
|
|
'element' => array( |
|
|
|
'name' => 'a', |
|
|
|
'text' => $url, |
|
|
|
'attributes' => array( |
|
|
|
'href' => $url, |
|
|
|
'data-link-text' => $url, |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
|
|
|
|
return $Inline; |
|
|
|
$Link = parent::inlineUrl($Excerpt); |
|
|
|
|
|
|
|
if (isset($Link)) { |
|
|
|
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']]; |
|
|
|
} |
|
|
|
return $Link; |
|
|
|
} |
|
|
|
|
|
|
|
protected function inlineUrlTag($Excerpt) |
|
|
|
{ |
|
|
|
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) |
|
|
|
{ |
|
|
|
$url = $matches[1]; |
|
|
|
|
|
|
|
return array( |
|
|
|
'extent' => strlen($matches[0]), |
|
|
|
'element' => array( |
|
|
|
'name' => 'a', |
|
|
|
'text' => $url, |
|
|
|
'attributes' => array( |
|
|
|
'href' => $url, |
|
|
|
'data-link-text' => $url, |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
$Link = parent::inlineUrlTag($Excerpt); |
|
|
|
|
|
|
|
if (isset($Link)) { |
|
|
|
$Link['element']['attributes'] += ['data-link-text' => $Link['element']['text']]; |
|
|
|
} |
|
|
|
return $Link; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |