Pārlūkot izejas kodu

fix(literalMidWordUnderscores): fix different behavior with asterisks

Closes #198
Estevão Soares dos Santos 9 gadi atpakaļ
vecāks
revīzija
e86aea8183

+ 2 - 2
dist/showdown.js

@@ -1829,8 +1829,8 @@ showdown.subParser('italicsAndBold', function (text, options) {
     text = text.replace(/(^|\s|>|\b)__(?=\S)([^]+?)__(?=\b|<|\s|$)/gm, '$1<strong>$2</strong>');
     text = text.replace(/(^|\s|>|\b)_(?=\S)([^]+?)_(?=\b|<|\s|$)/gm, '$1<em>$2</em>');
     //asterisks
-    text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>');
-    text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>');
+    text = text.replace(/(\*\*)(?=\S)([^\r]*?\S[*]*)\1/g, '<strong>$2</strong>');
+    text = text.replace(/(\*)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
 
   } else {
     // <strong> must go first:

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.js.map


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/showdown.min.js.map


+ 2 - 2
src/subParsers/italicsAndBold.js

@@ -7,8 +7,8 @@ showdown.subParser('italicsAndBold', function (text, options) {
     text = text.replace(/(^|\s|>|\b)__(?=\S)([^]+?)__(?=\b|<|\s|$)/gm, '$1<strong>$2</strong>');
     text = text.replace(/(^|\s|>|\b)_(?=\S)([^]+?)_(?=\b|<|\s|$)/gm, '$1<em>$2</em>');
     //asterisks
-    text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>');
-    text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>');
+    text = text.replace(/(\*\*)(?=\S)([^\r]*?\S[*]*)\1/g, '<strong>$2</strong>');
+    text = text.replace(/(\*)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>');
 
   } else {
     // <strong> must go first:

+ 5 - 0
test/features/#198.literalMidWordUnderscores-changes-behavior-of-asterisk.html

@@ -0,0 +1,5 @@
+<p>​pointer *ptr *thing</p>
+
+<p>something _else _bla</p>
+
+<p>something __else __bla</p>

+ 5 - 0
test/features/#198.literalMidWordUnderscores-changes-behavior-of-asterisk.md

@@ -0,0 +1,5 @@
+​pointer *ptr *thing
+
+something _else _bla
+
+something __else __bla

+ 2 - 0
test/node/testsuite.features.js

@@ -27,6 +27,8 @@ describe('makeHtml() features testsuite', function () {
       converter = new showdown.Converter({tasklists: true});
     } else if (testsuite[i].name === 'autolink-and-disallow-underscores') {
       converter = new showdown.Converter({literalMidWordUnderscores: true, simplifiedAutoLink: true});
+    } else if (testsuite[i].name === '#198.literalMidWordUnderscores-changes-behavior-of-asterisk') {
+      converter = new showdown.Converter({literalMidWordUnderscores: true});
     } else {
       converter = new showdown.Converter();
     }

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels