Răsfoiți Sursa

fix: lines with mutiple dashes being parsed as multilists

This input: `- - - a` causes trouble for the parser,
since it interprets it as multiple sublists, where it should
only interpert it as a list with a single list item.
This commit fixes this behavior.

Closes #312
Estevao Soares dos Santos 8 ani în urmă
părinte
comite
10b3410934

+ 17 - 0
dist/showdown.js

@@ -2007,6 +2007,18 @@ showdown.subParser('lists', function (text, options, globals) {
         });
       }
 
+      // ISSUE #312
+      // This input: - - - a
+      // causes trouble to the parser, since it interprets it as:
+      // <ul><li><li><li>a</li></li></li></ul>
+      // instead of:
+      // <ul><li>- - a</li></ul>
+      // So, to prevent it, we will put a marker (~A)in the beginning of the line
+      // Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser
+      item = item.replace(/^([-*+]|\d\.)[ \t]+[\s\n]*/g, function (wm2) {
+        return '~A' + wm2;
+      });
+
       // m1 - Leading line or
       // Has a double return (multi paragraph) or
       // Has sublist
@@ -2023,6 +2035,11 @@ showdown.subParser('lists', function (text, options, globals) {
           item = showdown.subParser('spanGamut')(item, options, globals);
         }
       }
+
+      // now we need to remove the marker (~A)
+      item = item.replace('~A', '');
+
+      // we can finally wrap the line in list item tags
       item =  '<li' + bulletStyle + '>' + item + '</li>\n';
       return item;
     });

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
dist/showdown.js.map


Fișier diff suprimat deoarece este prea mare
+ 0 - 0
dist/showdown.min.js


Fișier diff suprimat deoarece este prea mare
+ 0 - 0
dist/showdown.min.js.map


+ 17 - 0
src/subParsers/lists.js

@@ -70,6 +70,18 @@ showdown.subParser('lists', function (text, options, globals) {
         });
       }
 
+      // ISSUE #312
+      // This input: - - - a
+      // causes trouble to the parser, since it interprets it as:
+      // <ul><li><li><li>a</li></li></li></ul>
+      // instead of:
+      // <ul><li>- - a</li></ul>
+      // So, to prevent it, we will put a marker (~A)in the beginning of the line
+      // Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser
+      item = item.replace(/^([-*+]|\d\.)[ \t]+[\s\n]*/g, function (wm2) {
+        return '~A' + wm2;
+      });
+
       // m1 - Leading line or
       // Has a double return (multi paragraph) or
       // Has sublist
@@ -86,6 +98,11 @@ showdown.subParser('lists', function (text, options, globals) {
           item = showdown.subParser('spanGamut')(item, options, globals);
         }
       }
+
+      // now we need to remove the marker (~A)
+      item = item.replace('~A', '');
+
+      // we can finally wrap the line in list item tags
       item =  '<li' + bulletStyle + '>' + item + '</li>\n';
       return item;
     });

+ 15 - 0
test/issues/#312.spaced-dashes-followed-by-char.html

@@ -0,0 +1,15 @@
+<ul>
+<li>- - a</li>
+</ul>
+<p>a</p>
+<ul>
+<li>- * - - + a</li>
+</ul>
+<p>a</p>
+<ol>
+<li>2. 3. 4. 5.</li>
+</ol>
+<p>a</p>
+<ol>
+<li>2. 3. 4. 5. a</li>
+</ol>

+ 13 - 0
test/issues/#312.spaced-dashes-followed-by-char.md

@@ -0,0 +1,13 @@
+- - - a
+
+a
+
++ - * - - + a
+
+a
+
+1. 2. 3. 4. 5.
+
+a
+
+1. 2. 3. 4. 5. a

+ 8 - 0
test/issues/#312.spaced-dashes-followed-by-char2.html

@@ -0,0 +1,8 @@
+<ul>
+<li><p>- - a</p></li>
+<li><p>- * - - + a</p></li>
+</ul>
+<ol>
+<li><p>2. 3. 4. 5.</p></li>
+<li><p>2. 3. 4. 5. a</p></li>
+</ol>

+ 7 - 0
test/issues/#312.spaced-dashes-followed-by-char2.md

@@ -0,0 +1,7 @@
+- - - a
+
++ - * - - + a
+
+1. 2. 3. 4. 5.
+
+1. 2. 3. 4. 5. a

+ 10 - 0
test/issues/#312.spaced-dashes-followed-by-char3.html

@@ -0,0 +1,10 @@
+<ul>
+<li>-
+a</li>
+</ul>
+<p>fooo</p>
+<ul>
+<li><p>- - aaaaa</p>
+<p>bbbbb</p></li>
+</ul>
+

+ 10 - 0
test/issues/#312.spaced-dashes-followed-by-char3.md

@@ -0,0 +1,10 @@
+- - 
+a
+
+
+fooo
+
+
+- - - aaaaa
+
+   bbbbb

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff