Header anchors [needs discussion]
Author: puzrinCreated Jan 6, 2015Updated Feb 23, 2021
It's very popular request to add header ancors. Prior to do it, we need to discuss possible security problems and solutions.
Read first
- https://github.com/jch/html-pipeline/pull/111#issuecomment-34369984 - discussion about github implementation
- http://www.slideshare.net/x00mario/in-the-dom-no-one-will-hear-you-scream - awesome presentation about dom clobbering
Problems:
id- collisionsname- dom clobbering- cross-conflicts when multiple docs on the same page have the same headers
Possible solutions
- Do nothing
- unsafe, you need to control content, or site will be vulnerable
- Add prefix
- will require js to keep references work
- without js will make manual references typing not convenient
- does anyone type such way?
- not a problem for autogenerated tocs (we can add prefix to both anchors and refs)
- Add per-doc unique prefix
- not convenient in use. required in very limited cases
Need to discuss better solutions, and what to do by default, because anchors are really needed
current status
- Must have not empty default prefix
options.anchorPrefix- instance default.env.anchorPrefix- every-time-render override
- Open questions:
- default prefix name?
-or--of no objections (short and easy to type)
- should we autofix local relative anchor links? any bad side effects?
- default prefix name?
Source: markdown-it/markdown-it