瀏覽代碼

fix(literalMidWordAsterisks): fix option no longer treat punctuation as word character

Closes #398
Estevao Soares dos Santos 8 年之前
父節點
當前提交
8f05be7788

+ 6 - 6
dist/showdown.js

@@ -2342,14 +2342,14 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
 
   // Now parse asterisks
   if (options.literalMidWordAsterisks) {
-    text = text.trim().replace(/(?:^| +)\*{3}(\S[\s\S]*?)\*{3}(?: +|$)/g, function (wm, txt) {
-      return parseInside (txt, ' <strong><em>', '</em></strong> ');
+    text = text.trim().replace(/(^| )\*{3}(\S[\s\S]*?)\*{3}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
+      return parseInside (txt, lead + '<strong><em>', '</em></strong>' + trail);
     });
-    text = text.trim().replace(/(?:^| +)\*{2}(\S[\s\S]*?)\*{2}(?: +|$)/g, function (wm, txt) {
-      return parseInside (txt, ' <strong>', '</strong> ');
+    text = text.trim().replace(/(^| )\*{2}(\S[\s\S]*?)\*{2}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
+      return parseInside (txt, lead + '<strong>', '</strong>' + trail);
     });
-    text = text.trim().replace(/(?:^| +)\*{1}(\S[\s\S]*?)\*{1}(?: +|$)/g, function (wm, txt) {
-      return parseInside (txt, ' <em>', '</em>' + (wm.slice(-1) === ' ' ? ' ' : ''));
+    text = text.trim().replace(/(^| )\*(\S[\s\S]*?)\*([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
+      return parseInside (txt, lead + '<em>', '</em>' + trail);
     });
   } else {
     text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {

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


+ 6 - 6
src/subParsers/italicsAndBold.js

@@ -40,14 +40,14 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
 
   // Now parse asterisks
   if (options.literalMidWordAsterisks) {
-    text = text.trim().replace(/(?:^| +)\*{3}(\S[\s\S]*?)\*{3}(?: +|$)/g, function (wm, txt) {
-      return parseInside (txt, ' <strong><em>', '</em></strong> ');
+    text = text.trim().replace(/(^| )\*{3}(\S[\s\S]*?)\*{3}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
+      return parseInside (txt, lead + '<strong><em>', '</em></strong>' + trail);
     });
-    text = text.trim().replace(/(?:^| +)\*{2}(\S[\s\S]*?)\*{2}(?: +|$)/g, function (wm, txt) {
-      return parseInside (txt, ' <strong>', '</strong> ');
+    text = text.trim().replace(/(^| )\*{2}(\S[\s\S]*?)\*{2}([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
+      return parseInside (txt, lead + '<strong>', '</strong>' + trail);
     });
-    text = text.trim().replace(/(?:^| +)\*{1}(\S[\s\S]*?)\*{1}(?: +|$)/g, function (wm, txt) {
-      return parseInside (txt, ' <em>', '</em>' + (wm.slice(-1) === ' ' ? ' ' : ''));
+    text = text.trim().replace(/(^| )\*(\S[\s\S]*?)\*([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
+      return parseInside (txt, lead + '<em>', '</em>' + trail);
     });
   } else {
     text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {

+ 1 - 0
test/features/#398.literalMidWordAsterisks-treats-non-word-characters-as-characters.html

@@ -0,0 +1 @@
+<p>strippers, <strong>hitler</strong>, and stalin</p>

+ 1 - 0
test/features/#398.literalMidWordAsterisks-treats-non-word-characters-as-characters.md

@@ -0,0 +1 @@
+strippers, **hitler**, and stalin

+ 9 - 0
test/features/literalMidWordUnderscores.html

@@ -0,0 +1,9 @@
+<p>some <em>foo</em> yeah</p>
+<p>some <strong>foo</strong> yeah</p>
+<p>some <strong><em>foo</em></strong> yeah</p>
+<p>some word_foo_yeah</p>
+<p>some word__foo__yeah</p>
+<p>some word___foo___yeah</p>
+<p>strippers, <em>hitler</em>, and stalin</p>
+<p>strippers, <strong>hitler</strong>, and stalin</p>
+<p>strippers, <strong><em>hitler</em></strong>, and stalin</p>

+ 17 - 0
test/features/literalMidWordUnderscores.md

@@ -0,0 +1,17 @@
+some _foo_ yeah
+
+some __foo__ yeah
+
+some ___foo___ yeah
+
+some word_foo_yeah
+
+some word__foo__yeah
+
+some word___foo___yeah
+
+strippers, _hitler_, and stalin
+
+strippers, __hitler__, and stalin
+
+strippers, ___hitler___, and stalin

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

@@ -22,6 +22,8 @@ describe('makeHtml() features testsuite', function () {
         converter = new showdown.Converter({headerLevelStart: 3});
       } else if (testsuite[i].name === '#164.1.simple-autolink' || testsuite[i].name === '#204.certain-links-with-at-and-dot-break-url') {
         converter = new showdown.Converter({simplifiedAutoLink: true});
+      } else if (testsuite[i].name === 'literalMidWordUnderscores') {
+        converter = new showdown.Converter({literalMidWordUnderscores: true});
       } else if (testsuite[i].name === '#164.2.disallow-underscore-emphasis-mid-word') {
         converter = new showdown.Converter({literalMidWordUnderscores: true});
       } else if (testsuite[i].name === '#164.3.strikethrough' || testsuite[i].name === '#214.escaped-markdown-chars-break-strikethrough') {
@@ -84,6 +86,8 @@ describe('makeHtml() features testsuite', function () {
         converter = new showdown.Converter({backslashEscapesHTMLTags: true});
       } else if (testsuite[i].name === '#379.openLinksInNewWindow-breaks-em-markdup') {
         converter = new showdown.Converter({openLinksInNewWindow: true});
+      } else if (testsuite[i].name === '#398.literalMidWordAsterisks-treats-non-word-characters-as-characters') {
+        converter = new showdown.Converter({literalMidWordAsterisks: true});
       } else {
         converter = new showdown.Converter();
       }

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