1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Use rawHtml to provide conditional escaping for specialChars

This commit is contained in:
Aidan Woods 2018-03-18 22:44:07 +00:00
parent adcba80502
commit 011465bca6
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -964,13 +964,11 @@ class Parsedown
#
protected $InlineTypes = array(
'"' => array('SpecialCharacter'),
'!' => array('Image'),
'&' => array('SpecialCharacter'),
'*' => array('Emphasis'),
':' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'),
'>' => array('SpecialCharacter'),
'<' => array('UrlTag', 'EmailTag', 'Markup'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('Code'),
@ -980,7 +978,7 @@ class Parsedown
# ~
protected $inlineMarkerList = '!"*_&[:<>`~\\';
protected $inlineMarkerList = '!*_&[:<`~\\';
#
# ~
@ -1337,23 +1335,15 @@ class Parsedown
protected function inlineSpecialCharacter($Excerpt)
{
if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text']))
if (preg_match('/^&(#?+[0-9a-zA-Z]++);/', $Excerpt['text'], $matches))
{
return array(
'markup' => '&amp;',
'extent' => 1,
'element' => array('rawHtml' => '&'.$matches[1].';'),
'extent' => strlen($matches[0]),
);
}
$SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot');
if (isset($SpecialCharacter[$Excerpt['text'][0]]))
{
return array(
'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';',
'extent' => 1,
);
}
return;
}
protected function inlineStrikethrough($Excerpt)