evilstreak / markdown-js

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

How to create a numbered list? #229

Open Jakobud opened 9 years ago

Jakobud commented 9 years ago
  1. test
  2. test
  3. test

This creates a bullet list for me. How come this doesn't created a number 1,2,3 list?

ewels commented 9 years ago

I was just looking around for the same answer and the stumbled across the cause. I had the following:

* Bullet
* List

1. Numeric
2. List

This was being joined together as a single list, and so inheriting the bullet types from the first part. Separating it with another element (some text) split it into two lists and gave it the expected behaviour:

* Bullet
* List

Some text here

1. Numeric
2. List

There has to be another element between the lists, otherwise they join. You can have as many line breaks as you like between the lists, all that happens is that the 1. Numeric item is wrapped in a <p> tag.

Suggestions:

  1. Could the code detect a change in the type of list?
  2. Could there be a maximum of one empty line between list items?
ashb commented 9 years ago

This is definitely a bug. The list parsing code is the messiest part of this code - it gets nastily complex trying to deal with nested lists and paragraphs in lists etc.

@ewels thanks for the details test case! We should be able to do it as per your first suggestion.

ashb commented 9 years ago

Turns out we are 'bug compatible' with the original markdown implementation here: http://johnmacfarlane.net/babelmark2/?text=*+Bullet%0A*+List%0A%0A1.+Numeric%0A2.+List

I think this is probably a case where this behaviour is so unexpected that we should do it properly.