You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

markdown-it-anchor

Package Overview
Dependencies
Maintainers
2
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

markdown-it-anchor

Header anchors for markdown-it.

9.2.0
latest
Source
npmnpm
Version published
Weekly downloads
2.7M
12.99%
Maintainers
2
Weekly downloads
 
Created

What is markdown-it-anchor?

The markdown-it-anchor package is a plugin for the markdown-it Markdown parser that automatically adds anchor links to headings in your Markdown content. This is particularly useful for generating table of contents, permalinks, and improving navigation within long documents.

What are markdown-it-anchor's main functionalities?

Adding Anchor Links to Headings

This feature automatically adds anchor links to all headings in the Markdown content. The code sample demonstrates how to use the markdown-it-anchor plugin with markdown-it to process a simple Markdown string containing headings.

const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');

const md = markdownIt().use(markdownItAnchor);

const result = md.render('# Heading 1\n## Heading 2');
console.log(result);

Customizing Anchor Link Properties

This feature allows customization of the anchor links, such as adding a permalink symbol, setting a custom CSS class, and more. The code sample shows how to configure these options when initializing the plugin.

const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');

const md = markdownIt().use(markdownItAnchor, {
  permalink: true,
  permalinkClass: 'custom-class',
  permalinkSymbol: '🔗'
});

const result = md.render('# Heading 1\n## Heading 2');
console.log(result);

Slugification of Headings

This feature allows customization of the slugification process for generating anchor links. The code sample demonstrates how to provide a custom slugification function to the plugin.

const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');

const md = markdownIt().use(markdownItAnchor, {
  slugify: s => s.toLowerCase().replace(/[^a-z0-9]+/g, '-')
});

const result = md.render('# Custom Heading!\n## Another Heading');
console.log(result);

Other packages similar to markdown-it-anchor

Keywords

markdown

FAQs

Package last updated on 07 Sep 2024

Did you know?

Socket

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