Skip to content

Commit

Permalink
fix(lists): fix multi paragraph lists with sublists
Browse files Browse the repository at this point in the history
Paragraphed lists with sublists were being parsed incorrectly due to
workaround realted with simpleLineBreaks. This commit fixes this.

Closes #397
  • Loading branch information
tivie committed Jun 7, 2017
1 parent 5a5aff6 commit a2259c0
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 14 deletions.
11 changes: 6 additions & 5 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.

6 changes: 3 additions & 3 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.

4 changes: 1 addition & 3 deletions src/subParsers/lists.js
Expand Up @@ -93,16 +93,14 @@ showdown.subParser('lists', function (text, options, globals) {
item = showdown.subParser('lists')(item, options, globals);
item = item.replace(/\n$/, ''); // chomp(item)
item = showdown.subParser('hashHTMLBlocks')(item, options, globals);

// Colapse double linebreaks
item = item.replace(/\n\n+/g, '\n\n');
// replace double linebreaks with a placeholder
item = item.replace(/\n\n/g, '¨B');
if (isParagraphed) {
item = showdown.subParser('paragraphs')(item, options, globals);
} else {
item = showdown.subParser('spanGamut')(item, options, globals);
}
item = item.replace(/¨B/g, '\n\n');
}

// now we need to remove the marker (¨A)
Expand Down
5 changes: 4 additions & 1 deletion src/subParsers/spanGamut.js
Expand Up @@ -32,7 +32,10 @@ showdown.subParser('spanGamut', function (text, options, globals) {
// Do hard breaks
if (options.simpleLineBreaks) {
// GFM style hard breaks
text = text.replace(/\n/g, '<br />\n');
// only add line breaks if the text does not contain a block (special case for lists)
if (!/\n\n¨K/.test(text)) {
text = text.replace(/\n+/g, '<br />\n');
}
} else {
// Vanilla hard breaks
text = text.replace(/ +\n/g, '<br />\n');
Expand Down
14 changes: 14 additions & 0 deletions test/issues/#397.unordered-list-strange-behavior.html
@@ -0,0 +1,14 @@
<ul>
<li><p><strong>Customer</strong> – Opens the Customer List. Refer to the document “Customer Management”.</p>
<ul>
<li>Customer List</li>
<li>New Customer</li>
<li>Customer Prices</li>
<li>Appointments</li></ul></li>
<li><p><strong>Designer</strong> - Opens the Designer List. Refer to the document “Designer Commissions”.</p>
<ul>
<li>Designer List</li>
<li>New Designer</li>
<li>Designer Payment List</li>
<li>New Designer Payment</li></ul></li>
</ul>
11 changes: 11 additions & 0 deletions test/issues/#397.unordered-list-strange-behavior.md
@@ -0,0 +1,11 @@
- **Customer** – Opens the Customer List. Refer to the document “Customer Management”.
- Customer List
- New Customer
- Customer Prices
- Appointments

- **Designer** - Opens the Designer List. Refer to the document “Designer Commissions”.
- Designer List
- New Designer
- Designer Payment List
- New Designer Payment

0 comments on commit a2259c0

Please sign in to comment.