From 51a08fad85be42abf1db08f5e646118762a16a2f Mon Sep 17 00:00:00 2001
From: Emanuil Rusev
Date: Sat, 7 Dec 2013 17:21:36 +0200
Subject: [PATCH] improve parsing of emphasis
---
Parsedown.php | 13 +++++--------
tests/data/em_strong.html | 4 +++-
tests/data/em_strong.md | 6 +++++-
tests/data/emphasis.html | 3 ++-
tests/data/emphasis.md | 4 +++-
5 files changed, 18 insertions(+), 12 deletions(-)
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