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

querySelector fails for auto generated ids from sub sections headings that start with a number #258

Open
nborko opened this issue Aug 20, 2019 · 0 comments
Labels

Comments

@nborko
Copy link

nborko commented Aug 20, 2019

If a section heading starts with a number, e.g.

## 1. Section 1

The auto-generated ID of #1-section-1 is not a valid querySelector and throws an error when selected in the sidebar (in src/Home.vue#jumpToHash). So it needs to be quoted, e.g.

const el = document.querySelector(hash.replace(/^#\d/, m => '#\\' + m.charCodeAt(1).toString(16) + ' '))

(NOTE: CSS.escape will cover more cases, but the MDN compatibility matrix shows some notable holes, e.g. Safari on IOS, and the generated hash avoid most other issues anyway as far as I can tell)

Alternatively, a more robust hash could be generated in this situation. Or as a workaround, just never start a section heading with a number :-)

@egoist egoist added the bug label May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants