Add GitHub style anchor tags to headers
npm install --save @gerhobbelt/markdown-it-github-headings
var md = require('@gerhobbelt/markdown-it')() .use(require('@gerhobbelt/markdown-it-github-headings'), options) md.render('# hello')
Options and Defaults
The defaults will make the heading anchors behave as close to how GitHub behaves as possible.
||name of the class that will be added to the anchor tag||
||add a prefix to each heading ID. (see security note below)||
||Adds the icon next to each heading||
||reset the slugger counter between .render calls for duplicate headers. (See tests for example)||true|
Why should I prefix heading IDs?
If you have full control over the content, there is less of a risk, but be aware that strange bugs related to DOM Clobbering are still possible!
For more information, here are some good resources on the topic:
- User-generated content and DOM clobbering
- In the DOM, no one will hear you scream
- A discussion about GitHub implementation
- An open issue on markdown-it repo
But the prefixes make links look real gross.
Check out marky-deep-links for an example (works great with browserify or webpack).
Contributions welcome! Please read the contributing guidelines first.