Skip to content

Commit 7ee2017

Browse files
committed
fix(subParsers/italicsAndBold.js): fix broken em/strong tags when used with literalMidWordUnderscores
When literalMidWordUnderscoresis set to true, em and strong tags that start or end a paragraph don't get parsed as such. This fixes this issue. Closes #174
1 parent 47f3bbd commit 7ee2017

File tree

7 files changed

+21
-7
lines changed

7 files changed

+21
-7
lines changed

dist/showdown.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/subParsers/italicsAndBold.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ showdown.subParser('italicsAndBold', function (text, options) {
44
if (options.literalMidWordUnderscores) {
55
//underscores
66
// Since we are consuming a \s character, we need to add it
7-
text = text.replace(/(\s)__(?=\S)([^]+?)__(?=\s)/g, '$1<strong>$2</strong>');
8-
text = text.replace(/(\s)_(?=\S)([^]+?)_(?=\s)/g, '$1<em>$2</em>');
7+
text = text.replace(/(^|\s)__(?=\S)([^]+?)__(?=\s|$)/gm, '$1<strong>$2</strong>');
8+
text = text.replace(/(^|\s)_(?=\S)([^]+?)_(?=\s|$)/gm, '$1<em>$2</em>');
99
//asterisks
1010
text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>');
1111
text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>');

test/features/#164.2.disallow_underscore_emphasis_mid_word.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@
99
<p>this has just__one double underscore</p>
1010

1111
<p>this <strong>should be parsed</strong> as bold</p>
12+
13+
<p>emphasis at <em>end of sentence</em></p>
14+
15+
<p><em>emphasis at</em> line start</p>
16+
17+
<p>multi <em>line emphasis
18+
yeah it is</em> yeah</p>

test/features/#164.2.disallow_underscore_emphasis_mid_word.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ this is double__underscore__mid word
99
this has just__one double underscore
1010

1111
this __should be parsed__ as bold
12+
13+
emphasis at _end of sentence_
14+
15+
_emphasis at_ line start
16+
17+
multi _line emphasis
18+
yeah it is_ yeah

0 commit comments

Comments
 (0)