ndabas / toc

Table of Contents jQuery Plugin - A minimal, tiny jQuery plugin that will generate a table of contents, drawing from headings on the page.
https://ndabas.github.io/toc/
Apache License 2.0
84 stars 24 forks source link

Fixing headings with special characters #14

Closed juanruitina closed 4 years ago

juanruitina commented 4 years ago

Links to headings with special characters don't work. Removing everything that's not a-z characters and numbers in unique identifiers to avoid JS syntax error.

ndabas commented 4 years ago

Hi,

Thank you for your effort; however, the code was originally set to use alphanumeric IDs only and was later changed to allow any character except space, per the HTML5 spec. See the discussions below for more info:

https://github.com/ndabas/toc/pull/3#issuecomment-26796618 https://github.com/ndabas/toc/commit/c8992fa4216f2c81df0dfbcdee1ff7edb09a16ef

If you can see a problem -- can you please share a minimal repro, along with info on which browser(s) you see the issue on?

juanruitina commented 4 years ago

Hi Nikhil. You are absolutely right, this was unnecessary. I just found it was not working not because of the TOC plugin, but because of some other code. Sorry for this and thank you for your time. I'm closing the pull request.

In case it's of any interest: I added some code for smooth scrolling, but jQuery wasn't too happy with the IDs automatically generated by jquery.toc that contain special chars used in CSS notation nor with the percentage-encoded ones hash returns. So I had to escape the former and decode the latter, like this: decodeURIComponent( this.hash ).replace( /(:|\.|\[|\]|,|=|@|'|")/g, "\\$1" ) (sample in CodePen with jquery.toc)