mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
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:
parent
0a856d5394
commit
10b3410934
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -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
test/issues/#312.spaced-dashes-followed-by-char.html
Normal file
15
test/issues/#312.spaced-dashes-followed-by-char.html
Normal 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>
|
13
test/issues/#312.spaced-dashes-followed-by-char.md
Normal file
13
test/issues/#312.spaced-dashes-followed-by-char.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
- - - a
|
||||
|
||||
a
|
||||
|
||||
+ - * - - + a
|
||||
|
||||
a
|
||||
|
||||
1. 2. 3. 4. 5.
|
||||
|
||||
a
|
||||
|
||||
1. 2. 3. 4. 5. a
|
8
test/issues/#312.spaced-dashes-followed-by-char2.html
Normal file
8
test/issues/#312.spaced-dashes-followed-by-char2.html
Normal 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>
|
7
test/issues/#312.spaced-dashes-followed-by-char2.md
Normal file
7
test/issues/#312.spaced-dashes-followed-by-char2.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
- - - a
|
||||
|
||||
+ - * - - + a
|
||||
|
||||
1. 2. 3. 4. 5.
|
||||
|
||||
1. 2. 3. 4. 5. a
|
10
test/issues/#312.spaced-dashes-followed-by-char3.html
Normal file
10
test/issues/#312.spaced-dashes-followed-by-char3.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<ul>
|
||||
<li>-
|
||||
a</li>
|
||||
</ul>
|
||||
<p>fooo</p>
|
||||
<ul>
|
||||
<li><p>- - aaaaa</p>
|
||||
<p>bbbbb</p></li>
|
||||
</ul>
|
||||
|
10
test/issues/#312.spaced-dashes-followed-by-char3.md
Normal file
10
test/issues/#312.spaced-dashes-followed-by-char3.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
- -
|
||||
a
|
||||
|
||||
|
||||
fooo
|
||||
|
||||
|
||||
- - - aaaaa
|
||||
|
||||
bbbbb
|
Loading…
Reference in New Issue
Block a user