diff --git a/Parsedown.php b/Parsedown.php index 9059f51..918c7e6 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -605,19 +605,13 @@ class Parsedown $index ++; } } - - if (strpos($text, '*') !== FALSE) + + if (strpos($text, '*') !== FALSE or strpos($text, '_') !== FALSE) { - $text = preg_replace('/\*{2}(.*?)\*{2}/', '$1', $text); - $text = preg_replace('/\*(.*?)\*/', '$1', $text); + $text = preg_replace('/(\*\*|__)(.+?[*_]*)(?<=\S)\1/', '$2', $text); + $text = preg_replace('/(\*|_)(.+?)(?<=\S)\1/', '$2', $text); } - - if (strpos($text, '_') !== FALSE) - { - $text = preg_replace('/_{2}(\S.*?\S)_{2}/', '$1', $text); - $text = preg_replace('/_(\S.*?\S)_/', '$1', $text); - } - + $text = strtr($text, $map); return $text; diff --git a/tests/data/emphasis.html b/tests/data/emphasis.html index 2adbd1a..bcb613b 100644 --- a/tests/data/emphasis.html +++ b/tests/data/emphasis.html @@ -1,5 +1,8 @@

Here's an emphasis.

+

A short emphasis a b .

Here's a strong one.

Here's an emphasis that uses underscores.

Here's a strong emphasis that uses underscores.

-

This is _ not an emphasis _.

\ No newline at end of file +

This is _ not an emphasis _ neither is * that * .

+

Empty emphasis ** is not __ an emphasis.

+

Three asterisks are an emphasized asterisk * .

\ No newline at end of file diff --git a/tests/data/emphasis.md b/tests/data/emphasis.md index 45b57c0..1adc218 100644 --- a/tests/data/emphasis.md +++ b/tests/data/emphasis.md @@ -1,9 +1,15 @@ Here's *an emphasis*. +A short emphasis _a_ *b* . + Here's **a strong one**. Here's _an emphasis that uses underscores_. Here's __a strong emphasis that uses underscores__. -This is _ not an emphasis _. \ No newline at end of file +This is _ not an emphasis _ neither is * that * . + +Empty emphasis ** is not __ an emphasis. + +Three asterisks are an emphasized asterisk *** . \ No newline at end of file