Socket
Socket
Sign inDemoInstall

remark-slug

Package Overview
Dependencies
6
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    remark-slug

Add anchors to remark heading nodes


Version published
Weekly downloads
3.3M
decreased by-1.83%
Maintainers
1
Install size
71.4 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

remark-slug Build Status Coverage Status

:warning: mdast is currently being renamed to remark :warning:

This means all plug-ins and relating projects change too, causing many changes across the ecosystem. Expect the dust to settle in roughly a day.

See this project at the previous stable commit c4a51d1.

Add anchors to remark heading nodes.

Works great with remark-html, used by remark-toc and remark-man.

Installation

npm:

npm install remark-slug

remark-slug is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

Dependencies:

var slug = require('remark-slug');
var remark = require('remark');
var html = require('remark-html');

Process:

var doc = remark().use(slug).use(html).process('# Foo bar');

Yields:

<h1 id="foo-bar">Foo bar</h1>

CLI

remark ... -u remark-slug
remark ... -u 'remark-slug=library:"npm"'

API

remark.use(slug, options)

Adds slugs to markdown headings.

Sets data.id and data.htmlAttributes.id on heading nodes. The first can be used by any plugin as a unique identifier, the second tells remark-html to use its value as an id attribute. remark-slug does not overwrite these values when they already exist.

Parameters:

  • slug — This plugin;

  • options (Object?)

    • 'library' — (string or Function, default: 'github'):

      • 'github' — Slugs just like GitHub;

      • 'npm' — Slugs just like npm (caveat: npm doesn’t support links in headings, yet);

      • string (e.g., 'slug', 'slugg') — Library to require (not in the browser);

      • Function (e.g., require('slugg')) — Library to use.

License

MIT © Titus Wormer

Keywords

FAQs

Last updated on 24 Dec 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc