medfreeman / markdown-it-toc-and-anchor

markdown-it plugin to add a toc and anchor links in headings
MIT License
60 stars 35 forks source link

Automatic numbering #40

Open mpseidel opened 6 years ago

mpseidel commented 6 years ago

Hi guys - well done plugin, works great for my use case.

Quick question:

Would love to add an option to automatically number headings like this:

My TOC

  1. Section 1 1.1 Subsection 1 of 1 1.2 Subsection 2 of 1
  2. Section 2

1 Section 1

Section 1 contents here

1.2 Subsection 1 of 1

Contents of subsection 1 of 1 here

...

Any hints on how you would go about implementing this? Happy to give it a shot but maybe you can point me to some potential pitfalls or shortcuts before I dive in. Maybe I could add a callback function as an option to generate the number prefix based on level and counter ?