You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 1, 2024. It is now read-only.
remark plugin to add anchors headings using GitHub’s algorithm.
⚠️ Note: This is often useful when compiling to HTML.
If you’re doing that, it’s probably smarter to use
remark-rehype and rehype-slug and benefit
from the rehype ecosystem.
Note!
This plugin is ready for the new parser in remark
(remarkjs/remark#536).
No change is needed: it works exactly the same now as it did previously!
Install
This package is ESM only:
Node 12+ is needed to use it and it must be imported instead of required.
<h1id="lorem-ipsum-">Lorem ipsum 😪</h1><h2id="dolorsitamet">dolor—sit—amet</h2><h3id="consectetur--adipisicing">consectetur & adipisicing</h3><h4id="elit">elit</h4><h5id="elit-1">elit</h5>
API
This package exports no identifiers.
The default export is remarkSlug.
Sets data.id and data.hProperties.id on headings.
The first can be used by any plugin as a unique identifier, the second tells
mdast-util-to-hast (used in remark-html and
remark-rehype) to use its value as an id attribute.
Security
Use of remark-slug can open you up to a cross-site scripting (XSS)
attack as it sets id attributes on headings.
In a browser, elements are retrievable by id with JavaScript and CSS.
If a user injects a heading that slugs to an id you are already using,
the user content may impersonate the website.