Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

markdown-it-anchor

Package Overview
Dependencies
Maintainers
0
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
  • npm
  • Socket score

Version published
Weekly downloads
1.6M
decreased by-25.61%
Maintainers
0
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

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc