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

parse * and _ emphasis types separately to optimize performance and improve readability

This commit is contained in:
Emanuil 2013-09-03 00:14:04 +03:00
parent a94a45f955
commit 3afeee3b19

View File

@ -616,13 +616,19 @@ class Parsedown
$index ++; $index ++;
} }
} }
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)(.+?)(?<=\S)__/', '<strong>$1</strong>', $text);
$text = preg_replace('/(\*|_)(.+?)(?<=\S)\1/', '<em>$2</em>', $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); $text = strtr($text, $map);
return $text; return $text;