Browse Source

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
Estevão Soares dos Santos 10 years ago
parent
commit
7ee2017c56

+ 2 - 2
dist/showdown.js

@@ -1730,8 +1730,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>');

File diff suppressed because it is too large
+ 0 - 0
dist/showdown.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/showdown.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/showdown.min.js.map


+ 2 - 2
src/subParsers/italicsAndBold.js

@@ -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>');

+ 7 - 0
test/features/#164.2.disallow_underscore_emphasis_mid_word.html

@@ -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 - 0
test/features/#164.2.disallow_underscore_emphasis_mid_word.md

@@ -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

Some files were not shown because too many files changed in this diff