renettarenula / anchorific.js

⚓️ Generates anchored headings and nested anchored-based navigations based on header tags
MIT License
138 stars 30 forks source link

If several "h" have the same content, the same id gets generated, which breaks scrollspy #13

Open fnicollet opened 9 years ago

fnicollet commented 9 years ago

Hello and thanks for this useful library,

I have an issue, in my page i have several h4 which have exactly the same title. Anchrofic generates the exact same slug and because of that, the spy option will open several nodes (set as active) at the same time, which is not what I intended

If would be nice if slugs could be unique within one page such as "some-id" and "some-id2" or something

Fabien

renettarenula commented 9 years ago

Why would you set the title to the same name in the first place? Wouldn't that be confusing to your users? Just sayin'.

fnicollet commented 9 years ago

Hello,

It happens in like h4 or different h1s. Say you describe different parts of the interface in h1 and both have a way to "Add a filter". Then your subsection will have the same names

andrekako commented 1 month ago

We manage a site for a health department. Headings do repeat. It's inescapable.

Fanstastic commented 1 week ago

Hello, I have built upon @fnicollet 's functionality to handle headings with identical content and add a suffix to the slug. I needed this to work on all heading levels not just one level i.e. h2#identical and h2#identical-1, now we can have h2#identical and h2#identical-1 and also h3#identical-2.

43