npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rehype-beautiful-mermaid

v0.1.0

Published

Rehype plugin that renders Mermaid code blocks to inline SVG at build time

Readme

rehype-beautiful-mermaid

npm License: MIT

A rehype plugin that renders ```mermaid code blocks to inline SVG at build time using beautiful-mermaid.

beautiful-mermaid is an optional peer dependency. If it is not installed, mermaid code blocks are left unchanged so downstream plugins (e.g. @shikijs/rehype) can still process them as ordinary code blocks.

Installation

npm install rehype-beautiful-mermaid
# Install the rendering engine separately
npm install beautiful-mermaid

Usage

With notro (Astro + Notion)

Pass rehypeMermaid to notro() in astro.config.mjs. It must come before rehypeKatex and any syntax highlighter so that mermaid blocks are converted to SVG before other rehype plugins see them.

// astro.config.mjs
import { notro } from "notro-loader/integration";
import { rehypeMermaid } from "rehype-beautiful-mermaid";
import rehypeKatex from "rehype-katex";
import rehypeShiki from "@shikijs/rehype";

export default defineConfig({
  integrations: [
    notro({
      rehypePlugins: [
        [rehypeMermaid, { theme: "github-dark" }], // must come before rehypeShiki
        rehypeKatex,
        [rehypeShiki, { theme: "github-dark" }],
      ],
    }),
  ],
});

Standalone (any unified pipeline)

import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import rehypeStringify from "rehype-stringify";
import { rehypeMermaid } from "rehype-beautiful-mermaid";

const processor = unified()
  .use(remarkParse)
  .use(remarkRehype)
  .use(rehypeMermaid, { theme: "default" })
  .use(rehypeStringify);

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | theme | string | undefined | beautiful-mermaid theme key (e.g. "github-dark", "default"). Passed to beautiful-mermaid's THEMES map. | | className | string | "notro-mermaid" | CSS class applied to the <div> wrapper around each rendered SVG. |

How it works

  1. Visits all <pre><code class="language-mermaid"> nodes in the hast tree.
  2. Attempts to load beautiful-mermaid at runtime via a native ESM import (bypasses Vite's module runner so the plugin works correctly inside Astro's SSG prerender phase).
  3. If beautiful-mermaid is not installed or fails to load, the plugin exits early and leaves all mermaid blocks unchanged.
  4. For each mermaid block, calls renderMermaidSVG() to produce an SVG string, parses it into hast nodes, and replaces the <pre> block with a <div class="notro-mermaid"> containing the SVG.

Graceful fallback

If beautiful-mermaid is not installed, the plugin is a no-op. Mermaid code blocks remain as <pre><code class="language-mermaid"> and can be processed by a syntax highlighter or left as-is.

Relationship to notro

rehype-beautiful-mermaid is an optional add-on for the notro ecosystem. It has no dependency on notro and can be used in any rehype pipeline.