evilstreak / markdown-js

A Markdown parser for javascript
7.69k stars 863 forks source link

Consecutive lists produce broken code #150

Closed borisovg closed 10 years ago

borisovg commented 10 years ago

Single list:

var md = "* line 1\n* line 2\n* line 3\n* line 4";
console.log(markdown.toHTML(md));

produces

<ul><li>line 1</li><li>line 2</li><li>line 3</li><li>line 4</li></ul>

But 2 lists in a row:

var md = "* line 1\n* line 2\n\n* line 3\n* line 4";
console.log(markdown.toHTML(md));

produces

<ul><li>line 1</li><li><p>line 2</p></li><li><p>line 3</p></li><li>line 4</li></ul>
baldown commented 10 years ago

Similarly, and worse altogether, this produces broken code as well:

1. line 1
2. line 2

* line 3
* line 4

This really really needs fixed.

evilstreak commented 10 years ago

This behaviour is consistent with most other markdown implementations, including the original: http://johnmacfarlane.net/babelmark2/?normalize=1&text=*+line+1%0A*+line+2%0A%0A*+line+3%0A*+line+4

borisovg commented 10 years ago

If this behaviour is clearly broken then why not fix it?

evilstreak commented 10 years ago

Primarily because it follows a principle of least surprise. Markdown is a format implemented widely, by many other libraries than markdown-js, and people have an expectation that they are all implementing a common standard (even though the standard contains plenty of quirks, like this one). Matching the consensus (and especially the original) helps with that, except where the behaviour is really off the rails.

A second reason for this particular example is that I cannot see a solid use case for wanting multiple consecutive lists that aren't separated by other elements (such as a paragraph or a heading).