jgallen23 / toc

Table of Contents Plugin
http://projects.jga.me/toc/
MIT License
531 stars 111 forks source link

Verbose ids based on heading text #29

Closed wheresrhys closed 10 years ago

wheresrhys commented 10 years ago

So that internal links to headings can be written into the page's html it'd be useful if there was an option such as verbose-ids: true which would

  1. Read the heading's text
  2. Clean away any non alphanumeric characters
  3. Replace spaces by hyphens
  4. Use this (possibly prefixed bytoc-) as the id

If I get time this week I'll have a go at developing this myself and opening a pull request if you're open to the idea?

There's of course an issue with ensuring uniqueness of ids, but could be tackled by using the entire hierarchy as the id {{verbose h1}}/{{verbose h2}}... which assumes a good document structure, but as it would be a feature devs would turn on when it suits them I think this woudl be something for each dev to consider for themselves.

jgallen23 commented 10 years ago

this sounds great. Definitely open a pull request

wheresrhys commented 10 years ago

Great.

I had a bit of a rethink about naming conventions for ids - keeping a record of all ids created and incrementing to e.g. the-id-2 if there's a conflict would be a lot simpler to achieve, more bulletproof and more flexible as to the dev's choice of selectors, so will have a go at implementing that.

wheresrhys commented 10 years ago

https://github.com/jgallen23/toc/pull/30