Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CentralNic
parsedown
Commits
51a08fad
Commit
51a08fad
authored
Dec 07, 2013
by
Emanuil Rusev
Browse files
improve parsing of emphasis
parent
7fb08f33
Changes
5
Hide whitespace changes
Inline
Side-by-side
Parsedown.php
View file @
51a08fad
...
...
@@ -784,18 +784,15 @@ class Parsedown
if
(
strpos
(
$text
,
'_'
)
!==
FALSE
)
{
$text
=
preg_replace
(
'/__(?=\S)([^_]+?)(?<=\S)__/s'
,
'<strong>$1</strong>'
,
$text
,
-
1
,
$count
);
$count
or
$text
=
preg_replace
(
'/__(?=\S)(.+?)(?<=\S)__(?!_)/s'
,
'<strong>$1</strong>'
,
$text
);
$text
=
preg_replace
(
'/\b_(?=\S)(.+?)(?<=\S)_\b/s'
,
'<em>$1</em>'
,
$text
);
$text
=
preg_replace
(
'/(\b|_)_(?=\S)([^_]+?)(?<=\S)_(\b|_)/s'
,
'$1<em>$2</em>$3'
,
$text
);
$text
=
preg_replace
(
'/__(?=\S)([^_]+?)(?<=\S)__/s'
,
'<strong>$1</strong>'
,
$text
,
-
1
,
$count
);
}
if
(
strpos
(
$text
,
'*'
)
!==
FALSE
)
{
$text
=
preg_replace
(
'/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s'
,
'<strong>$1</strong>'
,
$text
,
-
1
,
$count
);
$count
or
$text
=
preg_replace
(
'/\*\*(?=\S)(.+?)(?<=\S)\*\*(?!\*)/s'
,
'<strong>$1</strong>'
,
$text
);
$text
=
preg_replace
(
'/\*(?=\S)([^*]+?)(?<=\S)\*/s'
,
'<em>$1</em>'
,
$text
,
-
1
,
$count
);
$count
or
$text
=
preg_replace
(
'/\*(?=\S)(.+?)(?<=\S)\*(?!\*)/s'
,
'<em>$1</em>'
,
$text
);
$text
=
preg_replace
(
'/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s'
,
'<strong>$1</strong>'
,
$text
);
$text
=
preg_replace
(
'/\*(?=\S)([^*]+?)(?<=\S)\*/s'
,
'<em>$1</em>'
,
$text
);
$text
=
preg_replace
(
'/\*\*(?=\S)([^*]+?)(?<=\S)\*\*/s'
,
'<strong>$1</strong>'
,
$text
);
}
$text
=
strtr
(
$text
,
$map
);
...
...
tests/data/em_strong.html
View file @
51a08fad
<p><strong><em>
em strong
</em>
strong
</strong></p>
<p><strong>
strong
<em>
em strong
</em></strong></p>
<p><strong>
strong
<em>
em strong
</em>
strong
</strong></p>
<p><strong>
strong
<em>
em strong
</em></strong></p>
\ No newline at end of file
<p><strong><em>
em strong
</em>
strong
</strong></p>
<p><strong>
strong
<em>
em strong
</em></strong></p>
<p><strong>
strong
<em>
em strong
</em>
strong
</strong></p>
\ No newline at end of file
tests/data/em_strong.md
View file @
51a08fad
...
...
@@ -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
tests/data/emphasis.html
View file @
51a08fad
...
...
@@ -3,4 +3,5 @@
emphasis
</em></p>
<p>
_ this _ is not an emphasis, neither is _ this_, _this _, or _this*
</p>
<p>
this_is_not_an_emphasis
</p>
<p>
an empty emphasis __ ** is not an emphasis
</p>
\ No newline at end of file
<p>
an empty emphasis __ ** is not an emphasis
</p>
<p>
*mixed *
<em>
double and
</em>
single asterisk** spans
</p>
\ No newline at end of file
tests/data/emphasis.md
View file @
51a08fad
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment