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