diff --git a/Parsedown.php b/Parsedown.php index 701a204..b58b7de 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -616,13 +616,19 @@ class Parsedown $index ++; } } - - if (strpos($text, '*') !== FALSE or strpos($text, '_') !== FALSE) + + if (strpos($text, '_') !== FALSE) { - $text = preg_replace('/(\*\*|__)(.+?[*_]*)(?<=\S)\1/', '$2', $text); - $text = preg_replace('/(\*|_)(.+?)(?<=\S)\1/', '$2', $text); + $text = preg_replace('/__(?=\S)(.+?)(?<=\S)__/', '$1', $text); + $text = preg_replace('/_(?=\S)(.+?)(?<=\S)_/', '$1', $text); } - + + if (strpos($text, '*') !== FALSE) + { + $text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*/', '$1', $text); + $text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*/', '$1', $text); + } + $text = strtr($text, $map); return $text;