Skip to content

Commit

Permalink
fix(lists): fix sublists inconsistent behavior
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tivie committed Nov 9, 2016
1 parent b7a69e2 commit 9cfe8b1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
12 changes: 4 additions & 8 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions src/subParsers/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
}
Expand All @@ -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);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* one
1. two

foo

* one
1. two

foo

* one
* two

0 comments on commit 9cfe8b1

Please sign in to comment.