Skip to content

Commit

Permalink
fix: lines with mutiple dashes being parsed as multilists
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tivie committed Dec 17, 2016
1 parent 0a856d5 commit 10b3410
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 3 deletions.
17 changes: 17 additions & 0 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.

2 changes: 1 addition & 1 deletion 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.

17 changes: 17 additions & 0 deletions src/subParsers/lists.js
Expand Up @@ -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
Expand All @@ -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;
});
Expand Down
15 changes: 15 additions & 0 deletions test/issues/#312.spaced-dashes-followed-by-char.html
@@ -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 changes: 13 additions & 0 deletions test/issues/#312.spaced-dashes-followed-by-char.md
@@ -0,0 +1,13 @@
- - - a

a

+ - * - - + a

a

1. 2. 3. 4. 5.

a

1. 2. 3. 4. 5. a
8 changes: 8 additions & 0 deletions test/issues/#312.spaced-dashes-followed-by-char2.html
@@ -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 changes: 7 additions & 0 deletions test/issues/#312.spaced-dashes-followed-by-char2.md
@@ -0,0 +1,7 @@
- - - a

+ - * - - + a

1. 2. 3. 4. 5.

1. 2. 3. 4. 5. a
10 changes: 10 additions & 0 deletions test/issues/#312.spaced-dashes-followed-by-char3.html
@@ -0,0 +1,10 @@
<ul>
<li>-
a</li>
</ul>
<p>fooo</p>
<ul>
<li><p>- - aaaaa</p>
<p>bbbbb</p></li>
</ul>

10 changes: 10 additions & 0 deletions test/issues/#312.spaced-dashes-followed-by-char3.md
@@ -0,0 +1,10 @@
- -
a


fooo


- - - aaaaa

bbbbb

0 comments on commit 10b3410

Please sign in to comment.