diff --git a/Parsedown.php b/Parsedown.php index 0ab3faf..1a182b0 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -779,14 +779,19 @@ class Parsedown if (strpos($text, '_') !== FALSE) { - $text = preg_replace('/__(?=\S)(.+?)(?<=\S)__(?!_)/s', '$1', $text); + $text = preg_replace('/__(?=\S)([^_]+?)(?<=\S)__/s', '$1', $text, -1, $count); + $count or $text = preg_replace('/__(?=\S)(.+?)(?<=\S)__(?!_)/s', '$1', $text); + $text = preg_replace('/\b_(?=\S)(.+?)(?<=\S)_\b/s', '$1', $text); } if (strpos($text, '*') !== FALSE) { - $text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s', '$1', $text); - $text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*/s', '$1', $text); + $text = preg_replace('/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s', '$1', $text, -1, $count); + $count or $text = preg_replace('/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s', '$1', $text); + + $text = preg_replace('/\*(?=\S)([^*]+?)(?<=\S)\*/s', '$1', $text, -1, $count); + $count or $text = preg_replace('/\*(?=\S)(.+?)(?<=\S)\*(?!\*)/s', '$1', $text); } $text = strtr($text, $map); diff --git a/tests/data/strong_em.html b/tests/data/strong_em.html new file mode 100644 index 0000000..87764fa --- /dev/null +++ b/tests/data/strong_em.html @@ -0,0 +1,6 @@ +

strong em

+

em strong em

+

strong em em

+

strong em

+

em strong em

+

strong em em

\ No newline at end of file diff --git a/tests/data/strong_em.md b/tests/data/strong_em.md new file mode 100644 index 0000000..4336eec --- /dev/null +++ b/tests/data/strong_em.md @@ -0,0 +1,11 @@ +***strong em*** + +*em **strong em*** + +***strong em** em* + +___strong em___ + +_em __strong em___ + +___strong em__ em_ \ No newline at end of file