Skip to content

Commit 9cfe8b1

Browse files
committed
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
1 parent b7a69e2 commit 9cfe8b1

7 files changed

Lines changed: 43 additions & 19 deletions

dist/showdown.js

Lines changed: 4 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/subParsers/lists.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ showdown.subParser('lists', function (text, options, globals) {
102102
*/
103103
function parseConsecutiveLists(list, listType, trimTrailing) {
104104
// check if we caught 2 or more consecutive lists by mistake
105-
// we use the counterRgx, meaning if listType is UL we look for UL and vice versa
106-
var counterRxg = (listType === 'ul') ? /^ {0,2}\d+\.[ \t]/gm : /^ {0,2}[*+-][ \t]/gm,
107-
subLists = [],
105+
// we use the counterRgx, meaning if listType is UL we look for OL and vice versa
106+
var counterRxg = (listType === 'ul') ? /^\d+\.[ \t]/gm : /^[*+-][ \t]/gm,
108107
result = '';
109108

110109
if (list.search(counterRxg) !== -1) {
@@ -124,9 +123,6 @@ showdown.subParser('lists', function (text, options, globals) {
124123
result += '\n<' + listType + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
125124
}
126125
})(list);
127-
for (var i = 0; i < subLists.length; ++i) {
128-
129-
}
130126
} else {
131127
result = '\n<' + listType + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
132128
}
@@ -151,7 +147,7 @@ showdown.subParser('lists', function (text, options, globals) {
151147
text = text.replace(wholeList, function (wholeMatch, m1, list, m3) {
152148

153149
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
154-
return parseConsecutiveLists(list, listType);
150+
return parseConsecutiveLists(list, listType, false);
155151
});
156152
}
157153

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<ul>
2+
<li>one</li>
3+
</ul>
4+
<ol>
5+
<li>two</li>
6+
</ol>
7+
<p>foo</p>
8+
<ul>
9+
<li>one
10+
11+
<ol>
12+
<li>two</li></ol></li>
13+
</ul>
14+
<p>foo</p>
15+
<ul>
16+
<li>one
17+
18+
<ul>
19+
<li>two</li></ul></li>
20+
</ul>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* one
2+
1. two
3+
4+
foo
5+
6+
* one
7+
1. two
8+
9+
foo
10+
11+
* one
12+
* two

0 commit comments

Comments
 (0)