Convert headings to permalinks
npm install makestatic-permalink> Convert headings to permalinks
For each heading in each matched HTML page assign it a unique id attribute and optionally convert the heading text to an anchor.
---
- Install
- API
- Permalink
- Permalink
- Options
- .sources
- License
---
```
yarn add makestatic-permalink
Convert headings to permalinks.
#### Permalink
`javascript`
new Permalink(context, options)
Create a Permalink plugin.
If a heading already has an id attribute it is not overwritten.
If the from and to options are given any headings falling outside thefrom
range are not modified. If you give and to values outside thefrom: 2
1-6 range they are clamped. These options are inclusive so setting and to: 3 will modify h2 and h3 elements only.
If the to value is less than the from value it is set to equal thefrom value. You cannot configure the range to select no elements.
The default slug implementation should work well but if you wish to use
your own these are the implementation details.
The slug function has the signature:
`javascript`
slug (element, text, seen, options = {})
Where element is the heading DOM element, text is the text for theid
element that should be used to generate the , seen is a map thatoptions
should be used to track duplicate identifiers and is alower
reference to the plugin instance. Implementations should respect the option.
The slug function must return a unique string identifier for the given
element.
* context Object the processing context.options
* Object plugin options.
##### Options
* from Number=1 start heading level.to
* Number=6 end heading level.link
* Boolean=true convert heading text to a link.classNames
* String=permalink class names for the link.lower
* Boolean=true convert id to lowercase.slug
* Function custom slug function.
#### .sources
`javascript`
Permalink.prototype.sources(file, context, options)
For each HTML file with an AST find matching headings and assign a
unique id attribute to the heading.
* file File the current file.context
* Object the processing context.options` Object plugin options.
*
MIT
---
Created by mkdoc on March 12, 2017
[docs]: https://makestatic.ws/docs/ "Documentation"
[standalone manual]: https://github.com/makestatic/website/blob/master/MANUAL.md "Standalone Manual"
[yarn]: https://yarnpkg.com "Yarn"
[webpack]: https://webpack.js.org "Webpack"
[babel]: https://babeljs.io "Babel"
[postcss]: http://postcss.org "Postcss"
[sugarss]: https://github.com/postcss/sugarss "Sugarss"
[reshape]: https://github.com/reshape/reshape "Reshape Source Code"
[reshapeml]: https://reshape.ml "Reshape"
[clean-css]: https://github.com/jakubpawlowicz/clean-css "Clean CSS"
[html-minifier]: https://github.com/kangax/html-minifier "Html Minifier"
[uglify-js]: https://github.com/mishoo/UglifyJS2 "Uglify JS"
[imagemin]: https://github.com/imagemin/imagemin "Imagemin"
[mkdoc]: https://github.com/mkdoc/mkdoc "Mkdoc"
[browsersync]: https://www.browsersync.io "Browsersync"
[yeoman]: http://yeoman.io "Yeoman"
[spike]: https://www.spike.cf "Spike"
[validator]: https://github.com/validator/validator "HTML Validator"
[github pages]: https://pages.github.com "Github Pages"
[amazon s3]: https://aws.amazon.com/s3/ "Amazon S3"
[google sitemaps]: https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 "Google Sitemaps"
[sitemaps]: https://www.sitemaps.org/ "Sitemaps"