parse * and _ emphasis types separately to optimize performance and improve readability
This commit is contained in:
parent
a94a45f955
commit
3afeee3b19
|
@ -617,10 +617,16 @@ class Parsedown
|
|||
}
|
||||
}
|
||||
|
||||
if (strpos($text, '*') !== FALSE or strpos($text, '_') !== FALSE)
|
||||
if (strpos($text, '_') !== FALSE)
|
||||
{
|
||||
$text = preg_replace('/(\*\*|__)(.+?[*_]*)(?<=\S)\1/', '<strong>$2</strong>', $text);
|
||||
$text = preg_replace('/(\*|_)(.+?)(?<=\S)\1/', '<em>$2</em>', $text);
|
||||
$text = preg_replace('/__(?=\S)(.+?)(?<=\S)__/', '<strong>$1</strong>', $text);
|
||||
$text = preg_replace('/_(?=\S)(.+?)(?<=\S)_/', '<em>$1</em>', $text);
|
||||
}
|
||||
|
||||
if (strpos($text, '*') !== FALSE)
|
||||
{
|
||||
$text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*/', '<strong>$1</strong>', $text);
|
||||
$text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*/', '<em>$1</em>', $text);
|
||||
}
|
||||
|
||||
$text = strtr($text, $map);
|
||||
|
|
Loading…
Reference in New Issue