This commit is contained in:
Stephen Sigwart 2020-09-05 21:40:11 +00:00 committed by GitHub
commit dbe7d4166e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 8 deletions

View File

@ -119,6 +119,15 @@ class Parsedown
'steam:',
);
protected $useTargetBlankLinks = false;
function setTargetBlankLinks($useTargetBlankLinks)
{
$this->useTargetBlankLinks = (bool)$useTargetBlankLinks;
return $this;
}
#
# Lines
#
@ -1274,6 +1283,16 @@ class Parsedown
}
}
protected function updateLinkAttributes($attributes)
{
if ($this->useTargetBlankLinks)
{
$attributes['target'] = '_blank';
$attributes['rel'] = 'noopener noreferrer';
}
return $attributes;
}
protected function inlineEmailTag($Excerpt)
{
$hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?';
@ -1296,9 +1315,9 @@ class Parsedown
'element' => array(
'name' => 'a',
'text' => $matches[1],
'attributes' => array(
'attributes' => $this->updateLinkAttributes(array(
'href' => $url,
),
)),
),
);
}
@ -1395,10 +1414,10 @@ class Parsedown
'destination' => 'elements',
),
'nonNestables' => array('Url', 'Link'),
'attributes' => array(
'attributes' => $this->updateLinkAttributes(array(
'href' => null,
'title' => null,
),
)),
);
$extent = 0;
@ -1547,9 +1566,9 @@ class Parsedown
'element' => array(
'name' => 'a',
'text' => $url,
'attributes' => array(
'attributes' => $this->updateLinkAttributes(array(
'href' => $url,
),
)),
),
);
@ -1568,9 +1587,9 @@ class Parsedown
'element' => array(
'name' => 'a',
'text' => $url,
'attributes' => array(
'attributes' => $this->updateLinkAttributes(array(
'href' => $url,
),
)),
),
);
}