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

rehype-highlight

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehype-highlight

rehype plugin to highlight code blocks with lowlight (highlight.js)

  • 7.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is rehype-highlight?

rehype-highlight is a plugin for the rehype ecosystem that provides syntax highlighting for code blocks in HTML. It uses the popular highlight.js library under the hood to perform the actual highlighting.

What are rehype-highlight's main functionalities?

Basic Syntax Highlighting

This feature allows you to add syntax highlighting to code blocks in your HTML. The code sample demonstrates how to use rehype-highlight to process an HTML string containing a JavaScript code block.

const rehype = require('rehype');
const rehypeHighlight = require('rehype-highlight');

rehype()
  .use(rehypeHighlight)
  .process('<pre><code class="language-js">const x = 42;</code></pre>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Custom Languages

This feature allows you to add custom languages for syntax highlighting. The code sample shows how to include a custom language definition and use it with rehype-highlight.

const rehype = require('rehype');
const rehypeHighlight = require('rehype-highlight');
const customLanguage = require('highlight.js/lib/languages/yourLanguage');

rehype()
  .use(rehypeHighlight, { languages: { yourLanguage: customLanguage } })
  .process('<pre><code class="language-yourLanguage">your code here</code></pre>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Custom Highlight.js Configuration

This feature allows you to configure highlight.js options, such as specifying a subset of languages to include. The code sample demonstrates how to limit the languages to JavaScript and Python.

const rehype = require('rehype');
const rehypeHighlight = require('rehype-highlight');

rehype()
  .use(rehypeHighlight, { subset: ['javascript', 'python'] })
  .process('<pre><code class="language-js">const x = 42;</code></pre>', function (err, file) {
    if (err) throw err;
    console.log(String(file));
  });

Other packages similar to rehype-highlight

Keywords

FAQs

Package last updated on 22 Oct 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