mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
implement link titles
This commit is contained in:
parent
be366b63ea
commit
c0b7155572
@ -401,11 +401,18 @@ class Parsedown
|
||||
|
||||
# reference
|
||||
|
||||
if (preg_match('/^\[(.+?)\]:[ ]*([^ ]+)/', $deindented_line, $matches))
|
||||
if (preg_match('/^\[(.+?)\]:[ ]*(.+?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*$/', $deindented_line, $matches))
|
||||
{
|
||||
$label = strtolower($matches[1]);
|
||||
|
||||
$this->reference_map[$label] = trim($matches[2], '<>');;
|
||||
$this->reference_map[$label] = array(
|
||||
'»' => trim($matches[2], '<>'),
|
||||
);
|
||||
|
||||
if (isset($matches[3]))
|
||||
{
|
||||
$this->reference_map[$label]['#'] = $matches[3];
|
||||
}
|
||||
|
||||
continue 2;
|
||||
}
|
||||
@ -734,10 +741,15 @@ class Parsedown
|
||||
|
||||
$remaining_text = substr($text, $offset);
|
||||
|
||||
if ($remaining_text[0] === '(' and preg_match('/^\((.*?)\)/', $remaining_text, $matches))
|
||||
if ($remaining_text[0] === '(' and preg_match('/\([ ]*(.*?)(?:[ ]+[\'"](.+?)[\'"])?[ ]*\)/', $remaining_text, $matches))
|
||||
{
|
||||
$element['»'] = $matches[1];
|
||||
|
||||
if (isset($matches[2]))
|
||||
{
|
||||
$element['#'] = $matches[2];
|
||||
}
|
||||
|
||||
$offset += strlen($matches[0]);
|
||||
}
|
||||
elseif ($this->reference_map)
|
||||
@ -755,7 +767,12 @@ class Parsedown
|
||||
|
||||
if (isset($this->reference_map[$reference]))
|
||||
{
|
||||
$element['»'] = $this->reference_map[$reference];
|
||||
$element['»'] = $this->reference_map[$reference]['»'];
|
||||
|
||||
if (isset($this->reference_map[$reference]['#']))
|
||||
{
|
||||
$element['#'] = $this->reference_map[$reference]['#'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -781,7 +798,9 @@ class Parsedown
|
||||
{
|
||||
$element['a'] = $this->parse_span_elements($element['a'], $markers);
|
||||
|
||||
$markup .= '<a href="'.$element['»'].'">'.$element['a'].'</a>';
|
||||
$markup .= isset($element['#'])
|
||||
? '<a href="'.$element['»'].'" title="'.$element['#'].'">'.$element['a'].'</a>'
|
||||
: '<a href="'.$element['»'].'">'.$element['a'].'</a>';
|
||||
}
|
||||
|
||||
unset($element);
|
||||
|
1
tests/data/inline_title.html
Normal file
1
tests/data/inline_title.html
Normal file
@ -0,0 +1 @@
|
||||
<p><a href="http://example.com" title="Example">single quotes</a> and <a href="http://example.com" title="Example">double quotes</a></p>
|
1
tests/data/inline_title.md
Normal file
1
tests/data/inline_title.md
Normal file
@ -0,0 +1 @@
|
||||
[single quotes](http://example.com 'Example') and [double quotes](http://example.com "Example")
|
1
tests/data/reference_title.html
Normal file
1
tests/data/reference_title.html
Normal file
@ -0,0 +1 @@
|
||||
<p><a href="http://example.com" title="Title">single quotes</a> and <a href="http://example.com" title="Title">double quotes</a></p>
|
1
tests/data/reference_title.md
Normal file
1
tests/data/reference_title.md
Normal file
@ -0,0 +1 @@
|
||||
[single quotes](http://example.com 'Title') and [double quotes](http://example.com "Title")
|
Loading…
Reference in New Issue
Block a user