瀏覽代碼

fix(literalMidWordAsterisks): no longer treats colon as alphanumeric char

Closes #461
Estevao Soares dos Santos 7 年之前
父節點
當前提交
21194c8a03

+ 7 - 7
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown v 1.8.2 - 16-11-2017 */
+;/*! showdown v 1.8.2 - 17-11-2017 */
 (function(){
 (function(){
 /**
 /**
  * Created by Tivie on 13-07-2015.
  * Created by Tivie on 13-07-2015.
@@ -3626,14 +3626,14 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
 
 
   // Now parse asterisks
   // Now parse asterisks
   if (options.literalMidWordAsterisks) {
   if (options.literalMidWordAsterisks) {
-    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.replace(/([^*]|^)\B\*\*\*(\S[\s\S]+?)\*\*\*\B(?!\*)/g, function (wm, lead, txt) {
+      return parseInside (txt, lead + '<strong><em>', '</em></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.replace(/([^*]|^)\B\*\*(\S[\s\S]+?)\*\*\B(?!\*)/g, function (wm, lead, txt) {
+      return parseInside (txt, lead + '<strong>', '</strong>');
     });
     });
-    text = text.trim().replace(/(^| )\*(\S[\s\S]*?)\*([ ,;!?.]|$)/g, function (wm, lead, txt, trail) {
-      return parseInside (txt, lead + '<em>', '</em>' + trail);
+    text = text.replace(/([^*]|^)\B\*(\S[\s\S]+?)\*\B(?!\*)/g, function (wm, lead, txt) {
+      return parseInside (txt, lead + '<em>', '</em>');
     });
     });
   } else {
   } else {
     text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {
     text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {

文件差異過大導致無法顯示
+ 0 - 0
dist/showdown.js.map


文件差異過大導致無法顯示
+ 0 - 1
dist/showdown.min.js


文件差異過大導致無法顯示
+ 0 - 0
dist/showdown.min.js.map


+ 6 - 6
src/subParsers/italicsAndBold.js

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

+ 5 - 0
test/features/literalMidWordAsterisks/basic.html

@@ -1,6 +1,11 @@
 <p>this is a sentence*with*mid asterisks</p>
 <p>this is a sentence*with*mid asterisks</p>
 <p>this is a sentence**with**two mid asterisks</p>
 <p>this is a sentence**with**two mid asterisks</p>
 <p>this is a sentence***with***three mid asterisks</p>
 <p>this is a sentence***with***three mid asterisks</p>
+<p>this is double*asterisk*mid word with another**asterisk**word</p>
+<p>this is double**asterisk**mid word with another**asterisk**word</p>
+<p>this is double***asterisk***mid word with another***asterisk***word</p>
+<p>this is double*asterisk**mid word with another***asterisk*word</p>
+<p>this is double**asterisk*mid word with another***asterisk**word</p>
 <p>this is a sentence with just*one asterisk</p>
 <p>this is a sentence with just*one asterisk</p>
 <p>this is a sentence with just**one asterisk</p>
 <p>this is a sentence with just**one asterisk</p>
 <p>this is a sentence with just***one asterisk</p>
 <p>this is a sentence with just***one asterisk</p>

+ 10 - 0
test/features/literalMidWordAsterisks/basic.md

@@ -4,6 +4,16 @@ this is a sentence**with**two mid asterisks
 
 
 this is a sentence***with***three mid asterisks
 this is a sentence***with***three mid asterisks
 
 
+this is double*asterisk*mid word with another**asterisk**word
+
+this is double**asterisk**mid word with another**asterisk**word
+
+this is double***asterisk***mid word with another***asterisk***word
+
+this is double*asterisk**mid word with another***asterisk*word
+
+this is double**asterisk*mid word with another***asterisk**word
+
 this is a sentence with just*one asterisk
 this is a sentence with just*one asterisk
 
 
 this is a sentence with just**one asterisk
 this is a sentence with just**one asterisk

+ 7 - 0
test/features/literalMidWordAsterisks/punctation-test.html

@@ -0,0 +1,7 @@
+<p><strong>Bold:</strong></p>
+<p><strong>Bold</strong></p>
+<p><strong>Bold</strong>:</p>
+<ul>
+    <li><strong>Bold</strong><ul>
+        <li>Tier 2</li></ul></li>
+</ul>

+ 8 - 0
test/features/literalMidWordAsterisks/punctation-test.md

@@ -0,0 +1,8 @@
+**Bold:**
+
+**Bold**
+
+**Bold**:
+
+- **Bold**
+    - Tier 2

+ 0 - 0
test/features/literalMidWordUnderscores.html → test/features/literalMidWordUnderscores/basic.html


+ 0 - 0
test/features/literalMidWordUnderscores.md → test/features/literalMidWordUnderscores/basic.md


+ 7 - 0
test/features/literalMidWordUnderscores/punctation-test.html

@@ -0,0 +1,7 @@
+<p><strong>Bold:</strong></p>
+<p><strong>Bold</strong></p>
+<p><strong>Bold</strong>:</p>
+<ul>
+    <li><strong>Bold</strong><ul>
+        <li>Tier 2</li></ul></li>
+</ul>

+ 8 - 0
test/features/literalMidWordUnderscores/punctation-test.md

@@ -0,0 +1,8 @@
+__Bold:__
+
+__Bold__
+
+__Bold__:
+
+- __Bold__
+    - Tier 2

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

@@ -13,6 +13,7 @@ var bootstrap = require('../bootstrap.js'),
     rawPrefixHeaderIdSuite = bootstrap.getTestSuite('test/features/rawPrefixHeaderId/'),
     rawPrefixHeaderIdSuite = bootstrap.getTestSuite('test/features/rawPrefixHeaderId/'),
     emojisSuite = bootstrap.getTestSuite('test/features/emojis/'),
     emojisSuite = bootstrap.getTestSuite('test/features/emojis/'),
     underlineSuite = bootstrap.getTestSuite('test/features/underline/'),
     underlineSuite = bootstrap.getTestSuite('test/features/underline/'),
+    literalMidWordUnderscoresSuite = bootstrap.getTestSuite('test/features/literalMidWordUnderscores/'),
     literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/');
     literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/');
 
 
 describe('makeHtml() features testsuite', function () {
 describe('makeHtml() features testsuite', function () {
@@ -211,6 +212,16 @@ describe('makeHtml() features testsuite', function () {
     }
     }
   });
   });
 
 
+  /** test literalMidWordUnderscores option **/
+  describe('literalMidWordUnderscores option', function () {
+    var converter,
+        suite = literalMidWordUnderscoresSuite;
+    for (var i = 0; i < suite.length; ++i) {
+      converter = new showdown.Converter({literalMidWordUnderscores: true});
+      it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
+    }
+  });
+
   /** test literalMidWordAsterisks option **/
   /** test literalMidWordAsterisks option **/
   describe('literalMidWordAsterisks option', function () {
   describe('literalMidWordAsterisks option', function () {
     var converter,
     var converter,

部分文件因文件數量過多而無法顯示