Skip to content

Commit

Permalink
fix(subParsers/italicsAndBold.js): fix broken em/strong tags when use…
Browse files Browse the repository at this point in the history
…d 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
  • Loading branch information
tivie committed Jul 14, 2015
1 parent 47f3bbd commit 7ee2017
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/subParsers/italicsAndBold.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ showdown.subParser('italicsAndBold', function (text, options) {
if (options.literalMidWordUnderscores) {
//underscores
// Since we are consuming a \s character, we need to add it
text = text.replace(/(\s)__(?=\S)([^]+?)__(?=\s)/g, '$1<strong>$2</strong>');
text = text.replace(/(\s)_(?=\S)([^]+?)_(?=\s)/g, '$1<em>$2</em>');
text = text.replace(/(^|\s)__(?=\S)([^]+?)__(?=\s|$)/gm, '$1<strong>$2</strong>');
text = text.replace(/(^|\s)_(?=\S)([^]+?)_(?=\s|$)/gm, '$1<em>$2</em>');
//asterisks
text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>');
text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
<p>this has just__one double underscore</p>

<p>this <strong>should be parsed</strong> as bold</p>

<p>emphasis at <em>end of sentence</em></p>

<p><em>emphasis at</em> line start</p>

<p>multi <em>line emphasis
yeah it is</em> yeah</p>
7 changes: 7 additions & 0 deletions test/features/#164.2.disallow_underscore_emphasis_mid_word.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ this is double__underscore__mid word
this has just__one double underscore

this __should be parsed__ as bold

emphasis at _end of sentence_

_emphasis at_ line start

multi _line emphasis
yeah it is_ yeah

0 comments on commit 7ee2017

Please sign in to comment.