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
This commit is contained in:
Estevao Soares dos Santos 2016-11-09 02:54:18 +00:00
parent b7a69e2dd6
commit 9cfe8b1412
7 changed files with 35 additions and 7 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

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

View File

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

View File

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