Add GitHub style anchor tags to headers
npm install markdown-it-github-headingsAdd GitHub style anchor tags to headers
[![npm][npm-image]][npm-url]
[![travis][travis-image]][travis-url]
[![standard][standard-image]][standard-url]
[npm-image]: https://img.shields.io/npm/v/markdown-it-github-headings.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/markdown-it-github-headings
[travis-image]: https://img.shields.io/travis/Flet/markdown-it-github-headings.svg?style=flat-square
[travis-url]: https://travis-ci.org/Flet/markdown-it-github-headings
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard
```
npm install markdown-it-github-headings
`js
var md = require('markdown-it')()
.use(require('markdown-it-github-headings'), options)
`
The defaults will make the heading anchors behave as close to how GitHub behaves as possible.
Name | Description | Default
------------------|----------------------------------------------------------------|-----------------------------------
className | name of the class that will be added to the anchor tag | anchorprefixHeadingIds | add a prefix to each heading ID. (see security note below) | trueprefix | if prefixHeadingIds is true, use this string to prefix each ID. | user-content-enableHeadingLinkIcons | Adds the icon next to each heading | truelinkIcon | If enableHeadingLinkIcons is true, use this to supply a custom icon (or anything really) | resetSlugger` | reset the slugger counter between .render calls for duplicate headers. (See tests for example) | true
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
Check out marky-deep-links for an example (works great with browserify or webpack).
Contributions welcome! Please read the contributing guidelines first.