egoist/docute

Do you want to work on this issue?

You can request for a bounty in order to promote it!

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

nborko posted onGitHub

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 :-)


Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests