Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quotes in headings produce errors #75

Open
kafoso opened this issue Jan 17, 2015 · 2 comments
Open

Quotes in headings produce errors #75

kafoso opened this issue Jan 17, 2015 · 2 comments

Comments

@kafoso
Copy link

kafoso commented Jan 17, 2015

Headings containing a (double) quote symbol, i.e. ", will produce an error.

This heading, for instance:

<h1>Bill "Bootstrap" Turner</h1>

... produces the error:

 Uncaught Error: Syntax error, unrecognized expression: div[data-unique="Bill"Bootstrap"Turner"]

This is likely due do the quote symbol not being escaped.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@kafoso kafoso changed the title Quotes in headings produce error Quotes in headings produce errors Jan 17, 2015
@micrology
Copy link

For me, it doesn't produce a Syntax error, but the link does not work, undoubtedly due to having quote marks in the link. I suggest that the hashGenerator functions provided are augmented to include a filter for quotes and apostrophes; this should cure the problem fairy easily.

@Tahiche
Copy link

Tahiche commented Jul 18, 2017

Hi,
I was randomly getting those errors and thanks to this post i figured it was because of the quotes in headers.
Seeing the advice from @micrology, it was easy to solve thanks to the "hashGenerator" API option. I just added a "replace" to further strip quotes and errors are gone.

//Calls the tocify method on your HTML div.
                $("#toc_content").tocify({
                    context: "#secc_content",
                    ignoreSelector: ".no_tocify",
                    // fix quotes in headings...
                    // function(text, element){} - Your own hash generation function that accepts the text as an
                    // argument, and returns the hash value.
                    hashGenerator:function(text, element){
                        // prettify the text - taken from tocify.js
                        var hashValue = text.toLowerCase().replace(/\s/g, "");
                       // strip single and double quotes...
                        hashValue = hashValue.replace(/["']/g,"");
                    return hashValue;
                    }
                });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants