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

Remove non-word character when toc sets up automatic IDs #7

Closed suuminbot closed 8 years ago

suuminbot commented 8 years ago

If heading includes non-word character, automatic IDs also includes these character.

For example, if I write heading like this. # hello? Then, ID will be like this. <h1 id="hello?">hello?</h1> If ID includes non-word character especially "?", some errors occur when I use other plugin.

How about to change regular expressions like this? var baseId = text.replace(/\s|[?]/g, "_"), suffix = "", count = 1;

ndabas commented 8 years ago

This is actually by design. The HTML5 spec permits any characters to be used in the ID, except for spaces. This plugin follows that spec.

If some other piece of code does not handle the HTML5 spec for IDs properly, you need to fix that code, or let the author of that code know.

suuminbot commented 8 years ago

I see. Thanks for the information. I'll check other one too. BY the way, I really appreciate this plugin. It's simple and easy to use. Thanks for sharing this code!

ndabas commented 8 years ago

Thank you for the appreciation! Happy to know that the plugin helped you.