Pārlūkot izejas kodu

fix(lists): fix sublists inconsistent behavior

Nested ul and ol lists behave inconsistently in the requirement
of having 3 spaces to be considered a nested list.
This fix changes the requirement to only one space in
both cases.

Closes #299
Estevao Soares dos Santos 8 gadi atpakaļ
vecāks
revīzija
9cfe8b1412

+ 4 - 8
dist/showdown.js

@@ -1,4 +1,4 @@
-;/*! showdown 02-11-2016 */
+;/*! showdown 09-11-2016 */
 (function(){
 /**
  * Created by Tivie on 13-07-2015.
@@ -2012,9 +2012,8 @@ showdown.subParser('lists', function (text, options, globals) {
    */
   function parseConsecutiveLists(list, listType, trimTrailing) {
     // check if we caught 2 or more consecutive lists by mistake
-    // we use the counterRgx, meaning if listType is UL we look for UL and vice versa
-    var counterRxg = (listType === 'ul') ? /^ {0,2}\d+\.[ \t]/gm : /^ {0,2}[*+-][ \t]/gm,
-      subLists = [],
+    // we use the counterRgx, meaning if listType is UL we look for OL and vice versa
+    var counterRxg = (listType === 'ul') ? /^\d+\.[ \t]/gm : /^[*+-][ \t]/gm,
       result = '';
 
     if (list.search(counterRxg) !== -1) {
@@ -2034,9 +2033,6 @@ showdown.subParser('lists', function (text, options, globals) {
           result += '\n<' + listType + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
         }
       })(list);
-      for (var i = 0; i < subLists.length; ++i) {
-
-      }
     } else {
       result = '\n<' + listType + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
     }
@@ -2061,7 +2057,7 @@ showdown.subParser('lists', function (text, options, globals) {
     text = text.replace(wholeList, function (wholeMatch, m1, list, m3) {
 
       var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
-      return parseConsecutiveLists(list, listType);
+      return parseConsecutiveLists(list, listType, false);
     });
   }
 

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
+ 1 - 1
dist/showdown.min.js


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


+ 3 - 7
src/subParsers/lists.js

@@ -102,9 +102,8 @@ showdown.subParser('lists', function (text, options, globals) {
    */
   function parseConsecutiveLists(list, listType, trimTrailing) {
     // check if we caught 2 or more consecutive lists by mistake
-    // we use the counterRgx, meaning if listType is UL we look for UL and vice versa
-    var counterRxg = (listType === 'ul') ? /^ {0,2}\d+\.[ \t]/gm : /^ {0,2}[*+-][ \t]/gm,
-      subLists = [],
+    // we use the counterRgx, meaning if listType is UL we look for OL and vice versa
+    var counterRxg = (listType === 'ul') ? /^\d+\.[ \t]/gm : /^[*+-][ \t]/gm,
       result = '';
 
     if (list.search(counterRxg) !== -1) {
@@ -124,9 +123,6 @@ showdown.subParser('lists', function (text, options, globals) {
           result += '\n<' + listType + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
         }
       })(list);
-      for (var i = 0; i < subLists.length; ++i) {
-
-      }
     } else {
       result = '\n<' + listType + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
     }
@@ -151,7 +147,7 @@ showdown.subParser('lists', function (text, options, globals) {
     text = text.replace(wholeList, function (wholeMatch, m1, list, m3) {
 
       var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
-      return parseConsecutiveLists(list, listType);
+      return parseConsecutiveLists(list, listType, false);
     });
   }
 

+ 20 - 0
test/issues/#299.nested-ordered-unordered-list-inconsistent-behavior.html

@@ -0,0 +1,20 @@
+<ul>
+    <li>one</li>
+</ul>
+<ol>
+    <li>two</li>
+</ol>
+<p>foo</p>
+<ul>
+    <li>one
+
+        <ol>
+            <li>two</li></ol></li>
+</ul>
+<p>foo</p>
+<ul>
+    <li>one
+
+        <ul>
+            <li>two</li></ul></li>
+</ul>

+ 12 - 0
test/issues/#299.nested-ordered-unordered-list-inconsistent-behavior.md

@@ -0,0 +1,12 @@
+* one
+1. two
+
+foo
+
+* one
+ 1. two
+
+foo
+
+* one
+ * two

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