What is remark-slug?
The remark-slug npm package is a plugin for the remark Markdown processor that automatically adds slugs to headings in a Markdown document. This is useful for generating links to specific sections of the document, enhancing navigation and accessibility.
What are remark-slug's main functionalities?
Automatic Slug Generation
This feature automatically generates slugs for each heading in a Markdown document. The code sample shows how to use remark-slug with remark and remark-html to convert a Markdown heading into HTML with a slug.
const remark = require('remark');
const remarkHtml = require('remark-html');
const remarkSlug = require('remark-slug');
remark()
.use(remarkSlug)
.use(remarkHtml)
.process('# Hello world', function (err, file) {
console.log(String(file));
});
Other packages similar to remark-slug
markdown-it-anchor
markdown-it-anchor is a plugin for the markdown-it Markdown parser. Similar to remark-slug, it adds anchors to headings in Markdown documents. While remark-slug is specifically designed for the remark ecosystem, markdown-it-anchor serves the markdown-it ecosystem, offering similar functionality but within a different processing environment.
rehype-slug
rehype-slug is a plugin for the rehype processor, which is part of the unified.js ecosystem, similar to remark. It adds slugs to HTML elements processed through rehype. This is akin to what remark-slug does but is applied directly to HTML rather than Markdown, making it suitable for projects that work with HTML content at a later stage in the content pipeline.
Deprecated: this package is no longer maintained.
Please use remark-rehype
to move from remark (markdown) to rehype (HTML)
and then replace remark-slug
with
rehype-slug
.
Git is still intact and previous versions can still be used without warnings.