瀏覽代碼

fix(lists): fix multi paragraph lists with sublists

Paragraphed lists with sublists were being parsed incorrectly due to
workaround realted with simpleLineBreaks. This commit fixes this.

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

+ 6 - 5
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 02-06-2017 */
+;/*! showdown 07-06-2017 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -2460,16 +2460,14 @@ showdown.subParser('lists', function (text, options, globals) {
         item = showdown.subParser('lists')(item, options, globals);
         item = item.replace(/\n$/, ''); // chomp(item)
         item = showdown.subParser('hashHTMLBlocks')(item, options, globals);
+
         // Colapse double linebreaks
         item = item.replace(/\n\n+/g, '\n\n');
-        // replace double linebreaks with a placeholder
-        item = item.replace(/\n\n/g, '¨B');
         if (isParagraphed) {
           item = showdown.subParser('paragraphs')(item, options, globals);
         } else {
           item = showdown.subParser('spanGamut')(item, options, globals);
         }
-        item = item.replace(/¨B/g, '\n\n');
       }
 
       // now we need to remove the marker (¨A)
@@ -2701,7 +2699,10 @@ showdown.subParser('spanGamut', function (text, options, globals) {
   // Do hard breaks
   if (options.simpleLineBreaks) {
     // GFM style hard breaks
-    text = text.replace(/\n/g, '<br />\n');
+    // only add line breaks if the text does not contain a block (special case for lists)
+    if (!/\n\n¨K/.test(text)) {
+      text = text.replace(/\n+/g, '<br />\n');
+    }
   } else {
     // Vanilla hard breaks
     text = text.replace(/  +\n/g, '<br />\n');

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


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


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


+ 1 - 3
src/subParsers/lists.js

@@ -93,16 +93,14 @@ showdown.subParser('lists', function (text, options, globals) {
         item = showdown.subParser('lists')(item, options, globals);
         item = item.replace(/\n$/, ''); // chomp(item)
         item = showdown.subParser('hashHTMLBlocks')(item, options, globals);
+
         // Colapse double linebreaks
         item = item.replace(/\n\n+/g, '\n\n');
-        // replace double linebreaks with a placeholder
-        item = item.replace(/\n\n/g, '¨B');
         if (isParagraphed) {
           item = showdown.subParser('paragraphs')(item, options, globals);
         } else {
           item = showdown.subParser('spanGamut')(item, options, globals);
         }
-        item = item.replace(/¨B/g, '\n\n');
       }
 
       // now we need to remove the marker (¨A)

+ 4 - 1
src/subParsers/spanGamut.js

@@ -32,7 +32,10 @@ showdown.subParser('spanGamut', function (text, options, globals) {
   // Do hard breaks
   if (options.simpleLineBreaks) {
     // GFM style hard breaks
-    text = text.replace(/\n/g, '<br />\n');
+    // only add line breaks if the text does not contain a block (special case for lists)
+    if (!/\n\n¨K/.test(text)) {
+      text = text.replace(/\n+/g, '<br />\n');
+    }
   } else {
     // Vanilla hard breaks
     text = text.replace(/  +\n/g, '<br />\n');

+ 14 - 0
test/issues/#397.unordered-list-strange-behavior.html

@@ -0,0 +1,14 @@
+<ul>
+    <li><p><strong>Customer</strong> – Opens the Customer List. Refer to the document “Customer Management”.</p>
+        <ul>
+            <li>Customer List</li>
+            <li>New Customer</li>
+            <li>Customer Prices</li>
+            <li>Appointments</li></ul></li>
+    <li><p><strong>Designer</strong> - Opens the Designer List. Refer to the document “Designer Commissions”.</p>
+        <ul>
+            <li>Designer List</li>
+            <li>New Designer</li>
+            <li>Designer Payment List</li>
+            <li>New Designer Payment</li></ul></li>
+</ul>

+ 11 - 0
test/issues/#397.unordered-list-strange-behavior.md

@@ -0,0 +1,11 @@
+- **Customer** – Opens the Customer List. Refer to the document “Customer Management”.
+    - Customer List
+    - New Customer
+    - Customer Prices
+    - Appointments
+
+- **Designer** - Opens the Designer List. Refer to the document “Designer Commissions”.
+    - Designer List
+    - New Designer
+    - Designer Payment List
+    - New Designer Payment

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