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
This commit is contained in:
Estevao Soares dos Santos 2016-12-17 05:20:23 +00:00
parent 0a856d5394
commit 10b3410934
11 changed files with 80 additions and 0 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -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;
});

View File

@ -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>

View File

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

View File

@ -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>

View File

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

View File

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

View File

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