mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Implement Link
This commit is contained in:
@ -444,70 +444,6 @@ class Parsedown
|
||||
return $Inline;
|
||||
}
|
||||
|
||||
protected function inlineLink($Excerpt)
|
||||
{
|
||||
$Element = [
|
||||
'name' => 'a',
|
||||
'handler' => [
|
||||
'function' => 'lineElements',
|
||||
'argument' => null,
|
||||
'destination' => 'elements',
|
||||
],
|
||||
'nonNestables' => ['Url', 'Link'],
|
||||
'attributes' => [
|
||||
'href' => null,
|
||||
'title' => null,
|
||||
],
|
||||
];
|
||||
|
||||
$extent = 0;
|
||||
|
||||
$remainder = $Excerpt['text'];
|
||||
|
||||
if (\preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) {
|
||||
$Element['handler']['argument'] = $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['handler']['argument'];
|
||||
$definition = \strtolower($definition);
|
||||
|
||||
$extent += \strlen($matches[0]);
|
||||
} else {
|
||||
$definition = \strtolower($Element['handler']['argument']);
|
||||
}
|
||||
|
||||
if (! isset($this->DefinitionData['Reference'][$definition])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$Definition = $this->DefinitionData['Reference'][$definition];
|
||||
|
||||
$Element['attributes']['href'] = $Definition['url'];
|
||||
$Element['attributes']['title'] = $Definition['title'];
|
||||
}
|
||||
|
||||
return [
|
||||
'extent' => $extent,
|
||||
'element' => $Element,
|
||||
];
|
||||
}
|
||||
|
||||
protected function inlineMarkup($Excerpt)
|
||||
{
|
||||
if ($this->markupEscaped or $this->safeMode or \strpos($Excerpt['text'], '>') === false) {
|
||||
|
Reference in New Issue
Block a user