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

Better parsing of emphasis and strong elements

- Regex is based on original Perl regex.
 - Added more tests.
This commit is contained in:
hkdobrev
2013-07-22 21:29:32 +03:00
parent 99bf0d4bba
commit 7ace421f6d
3 changed files with 16 additions and 13 deletions

View File

@@ -605,19 +605,13 @@ class Parsedown
$index ++;
}
}
if (strpos($text, '*') !== FALSE)
if (strpos($text, '*') !== FALSE or strpos($text, '_') !== FALSE)
{
$text = preg_replace('/\*{2}(.*?)\*{2}/', '<strong>$1</strong>', $text);
$text = preg_replace('/\*(.*?)\*/', '<em>$1</em>', $text);
$text = preg_replace('/(\*\*|__)(.+?[*_]*)(?<=\S)\1/', '<strong>$2</strong>', $text);
$text = preg_replace('/(\*|_)(.+?)(?<=\S)\1/', '<em>$2</em>', $text);
}
if (strpos($text, '_') !== FALSE)
{
$text = preg_replace('/_{2}(\S.*?\S)_{2}/', '<strong>$1</strong>', $text);
$text = preg_replace('/_(\S.*?\S)_/', '<em>$1</em>', $text);
}
$text = strtr($text, $map);
return $text;