bevacqua / woofmark

:dog2: Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor
https://bevacqua.github.io/woofmark
MIT License
1.62k stars 74 forks source link

Use start= attribute of <ol> to enable numbered lists that start with non-1 digits #66

Open jywarren opened 6 years ago

jywarren commented 6 years ago

(ref https://github.com/publiclab/PublicLab.Editor/issues/128)

In GitHub Markdown, there's a nice feature where you can start a list with a non-1 digit and it starts numbering there. As a step in that direction, when parsing Markdown lists, can we not convert to 1,2,3,4 automatically? The megamark parser should be able to read it anyways, so if we take a list like:

3. hi
4. hi
5. hi

...is there any way to preserve that numbering while in rich mode? Perhaps by storing the number in a <li data-numeral="3"> type attribute?

Just by way of example:

  1. hi
  2. hi
  3. hi
jywarren commented 6 years ago

Aha -- examining GitHub's work, the list starts with <ol start="3"> -- I imagine that's a standard HTML way to do this. Could that work?

jywarren commented 6 years ago

This line seems like where we could start:

https://github.com/bevacqua/woofmark/blob/b58efb794f7610c92d70bec435cfd021ab45673c/src/html/list.js#L12

and correspondingly on converting to Markdown, here we'd have to read the start attribute and offest the numerals shown:

https://github.com/bevacqua/woofmark/blob/2d932112d44c7f72ccc9e23daf6749b9cc8bcdde/src/markdown/list.js#L31-L34

jywarren commented 6 years ago

@bevacqua what do you think of this solution? Not urgent but if you +1 I can open a PR!