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
This commit is contained in:
Estevão Soares dos Santos 2015-07-14 16:51:26 +01:00
parent 47f3bbd2c6
commit 7ee2017c56
7 changed files with 16 additions and 2 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -4,8 +4,8 @@ showdown.subParser('italicsAndBold', function (text, options) {
if (options.literalMidWordUnderscores) { if (options.literalMidWordUnderscores) {
//underscores //underscores
// Since we are consuming a \s character, we need to add it // 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|$)/gm, '$1<strong>$2</strong>');
text = text.replace(/(\s)_(?=\S)([^]+?)_(?=\s)/g, '$1<em>$2</em>'); text = text.replace(/(^|\s)_(?=\S)([^]+?)_(?=\s|$)/gm, '$1<em>$2</em>');
//asterisks //asterisks
text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>'); text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>');
text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>'); text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>');

View File

@ -9,3 +9,10 @@
<p>this has just__one double underscore</p> <p>this has just__one double underscore</p>
<p>this <strong>should be parsed</strong> as bold</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>

View File

@ -9,3 +9,10 @@ this is double__underscore__mid word
this has just__one double underscore this has just__one double underscore
this __should be parsed__ as bold this __should be parsed__ as bold
emphasis at _end of sentence_
_emphasis at_ line start
multi _line emphasis
yeah it is_ yeah