yogthos / markdown-clj

Markdown parser in Clojure
Eclipse Public License 1.0
540 stars 120 forks source link

Ordered and unordered lists are combined unless separated by three newlines #170

Open noahmoss opened 3 years ago

noahmoss commented 3 years ago

Hello!

I noticed this behavior, which is not what I would have expected:

> (markdown.core/md-to-html-string "1. one\n2. two\n\n* three\n* four")
"<ol><li>one</li><li>two</li><li>three</li><li>four</li></ol>"

> (markdown.core/md-to-html-string "1. one\n2. two\n\n\n* three\n* four")
"<ol><li>one</li><li>two</li></ol><ul><li>three</li><li>four</li></ul>"

Most markdown parsers, as far as I can tell, will keep the ordered and unordered lists separate if there's even just a single newline between them.

Would you consider this a bug?

yogthos commented 3 years ago

That does look like an unintended behavior that slipped by, and I'm open to updating the parser to be inline with other parsers. I might not have the time to look at this in the near future, but I could help guide a PR if you'd be interested at taking a look. :)

noahmoss commented 3 years ago

@yogthos I'd be happy to contribute! If you have any pointers to where changes would have to be made, that would be great.

yogthos commented 3 years ago

Fantastic, and this is probably a good place to start. The parser analyzes text line by line, and the function takes two arguments which are text and state. The text is the current line, and the state is a map specifying what the state of the parser currently is. So, the trick would be to identify when the next line shouldn't be treated as part of the current list.