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

rehype-autolink-headings

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-autolink-headings

rehype plugin to add links to headings

  • 7.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is rehype-autolink-headings?

The rehype-autolink-headings package is a plugin for the rehype ecosystem that automatically adds links to headings in HTML documents. This is particularly useful for generating anchor links for headings in markdown files that are converted to HTML, making it easier to navigate through long documents.

What are rehype-autolink-headings's main functionalities?

Basic Usage

This code demonstrates the basic usage of rehype-autolink-headings. It processes an HTML string containing headings and automatically adds anchor links to those headings.

const rehype = require('rehype');
const rehypeAutolinkHeadings = require('rehype-autolink-headings');

rehype()
  .use(rehypeAutolinkHeadings)
  .process('<h1>Title</h1><h2>Subtitle</h2>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Customizing Link Properties

This example shows how to customize the behavior of the links added to the headings. The 'behavior' option is set to 'wrap', which wraps the heading text with the anchor link.

const rehype = require('rehype');
const rehypeAutolinkHeadings = require('rehype-autolink-headings');

rehype()
  .use(rehypeAutolinkHeadings, { behavior: 'wrap' })
  .process('<h1>Title</h1><h2>Subtitle</h2>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Adding Custom Properties to Links

This example demonstrates how to add custom properties to the generated links. Here, a custom class name 'custom-class' is added to the anchor links.

const rehype = require('rehype');
const rehypeAutolinkHeadings = require('rehype-autolink-headings');

rehype()
  .use(rehypeAutolinkHeadings, { properties: { className: 'custom-class' } })
  .process('<h1>Title</h1><h2>Subtitle</h2>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Other packages similar to rehype-autolink-headings

Keywords

FAQs

Package last updated on 08 Nov 2023

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