diff --git a/Parsedown.php b/Parsedown.php index 5bd91b5..ce368e5 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -784,18 +784,15 @@ class Parsedown if (strpos($text, '_') !== FALSE) { $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); + $text = preg_replace('/(\b|_)_(?=\S)([^_]+?)(?<=\S)_(\b|_)/s', '$1$2$3', $text); + $text = preg_replace('/__(?=\S)([^_]+?)(?<=\S)__/s', '$1', $text, -1, $count); } if (strpos($text, '*') !== FALSE) { - $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 = preg_replace('/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s', '$1', $text); + $text = preg_replace('/\*(?=\S)([^*]+?)(?<=\S)\*/s', '$1', $text); + $text = preg_replace('/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s', '$1', $text); } $text = strtr($text, $map); diff --git a/tests/data/em_strong.html b/tests/data/em_strong.html index 5760332..adc08ce 100644 --- a/tests/data/em_strong.html +++ b/tests/data/em_strong.html @@ -1,4 +1,6 @@

em strong strong

strong em strong

strong em strong strong

-

strong em strong

\ No newline at end of file +

em strong strong

+

strong em strong

+

strong em strong strong

\ No newline at end of file diff --git a/tests/data/em_strong.md b/tests/data/em_strong.md index 837e1e6..748190c 100644 --- a/tests/data/em_strong.md +++ b/tests/data/em_strong.md @@ -4,4 +4,8 @@ __strong _em strong___ __strong _em strong_ strong__ -**strong *em strong*** \ No newline at end of file +***em strong* strong** + +**strong *em strong*** + +**strong *em strong* strong** \ No newline at end of file diff --git a/tests/data/emphasis.html b/tests/data/emphasis.html index ce129c9..a5f107b 100644 --- a/tests/data/emphasis.html +++ b/tests/data/emphasis.html @@ -3,4 +3,5 @@ emphasis

_ this _ is not an emphasis, neither is _ this_, _this _, or _this*

this_is_not_an_emphasis

-

an empty emphasis __ ** is not an emphasis

\ No newline at end of file +

an empty emphasis __ ** is not an emphasis

+

*mixed *double and single asterisk** spans

\ No newline at end of file diff --git a/tests/data/emphasis.md b/tests/data/emphasis.md index dfbeea3..132681d 100644 --- a/tests/data/emphasis.md +++ b/tests/data/emphasis.md @@ -7,4 +7,6 @@ _ this _ is not an emphasis, neither is _ this_, _this _, or _this* this_is_not_an_emphasis -an empty emphasis __ ** is not an emphasis \ No newline at end of file +an empty emphasis __ ** is not an emphasis + +*mixed **double and* single asterisk** spans \ No newline at end of file