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

@xingwangzhe/satteri-mermaid

v0.2.9

Published

Satteri MDAST plugin for Mermaid diagram detection and transformation

Readme

@xingwangzhe/satteri-mermaid

Sätteri MDAST + HAST plugin for Mermaid diagram detection and transformation.

Features

  • Dual-plugin architecture — MDAST plugin for detection, HAST plugin for safe rendering
  • Immune to Sätteri text transforms — mermaid code is inserted after Sätteri processing, so {" diamond nodes survive
  • Zero-configmermaidMdast() + mermaidHast() just work
  • Feature detectionpopFlags() tells you whether the page has diagrams, so you can lazy-load mermaid
  • Isolated instances — each factory call returns an independent plugin instance
  • TypeScript — fully typed

Install

bun add @xingwangzhe/satteri-mermaid

Requires satteri >= 0.8.0 and mermaid >= 11.0.0 as peer dependencies.

Usage

Recommended (MDAST + HAST, since v0.2.0)

// astro.config.mjs
import { mermaidMdast, mermaidHast } from "@xingwangzhe/satteri-mermaid";

export default defineConfig({
  markdown: {
    processor: satteri({
      mdastPlugins: [katex(), mermaidMdast()],
      hastPlugins: [photoswipe(), mermaidHast()],
    }),
  },
});

Why MDAST + HAST?

Sätteri applies text transformations (like converting {" to curly-quote equivalents) to all raw HTML content produced by MDAST plugins. This corrupts mermaid diamond-node syntax (C{"label"}C{'{'}"label"{'}'}), causing browser-side "Syntax error".

The solution: the MDAST plugin only outputs an empty <pre class="mermaid"> placeholder and stores the mermaid code in ctx.data. The HAST plugin runs after all Sätteri processing is complete, reads the code from ctx.data, and populates the <pre> element — safely bypassing any text transforms. See How It Works for a visual overview.

Advanced (with feature detection)

import { createMermaidMdastPlugin, createMermaidHastPlugin } from "@xingwangzhe/satteri-mermaid";

const { plugin: mdastPlugin, popFlags } = createMermaidMdastPlugin({ langs: ["mermaid"] });
const { plugin: hastPlugin } = createMermaidHastPlugin();

// Register plugins:
//   mdastPlugins: [mdastPlugin],
//   hastPlugins:  [hastPlugin],

// After processing:
const { hasMermaid } = popFlags();
if (hasMermaid) {
  await import("mermaid");
  mermaid.run({ querySelector: ".mermaid" });
}

How It Works

flowchart TD
    subgraph MD["1. Markdown"]
        SRC["mermaid code block
in Markdown source"]
    end

    subgraph MDAST["2. MDAST Plugin"]
        STORE["store code in ctx.data"]
        EMPTY["output empty pre placeholder"]
    end

    subgraph SAT["3. Sätteri Processing"]
        SAFE["no {&quot; pattern to corrupt"]
    end

    subgraph HAST["4. HAST Plugin"]
        READ["read code from ctx.data"]
        FILL["populate pre with real code"]
    end

    subgraph BROWSER["5. Browser"]
        HTML["pre.mermaid element
with clean code"]
        MM["mermaid.run()"]
        SVG["SVG diagram"]
    end

    MD --> MDAST --> SAT --> HAST --> BROWSER

API

mermaidMdast(options?)

Factory function. Returns a Sätteri MDAST plugin. Register in mdastPlugins.

mermaidHast(options?)

Factory function. Returns a Sätteri HAST plugin. Register in hastPlugins.

Shared Options

| Option | Type | Default | Description | | ------- | ---------- | ------------- | ------------------------------- | | langs | string[] | ["mermaid"] | Code block language identifiers |

createMermaidMdastPlugin(options?)

Returns { plugin, popFlags }. Use this when you need popFlags for feature detection.

createMermaidHastPlugin(options?)

Returns { plugin }. Companion HAST plugin for the MDAST one above.

popFlags(): MermaidFlags

Returns { hasMermaid: boolean } and resets internal state.

Migration (v0.1.x → v0.2.0)

Before:

import { mermaid } from "@xingwangzhe/satteri-mermaid";

mdastPlugins: [katex(), mermaid()],

After:

import { mermaidMdast, mermaidHast } from "@xingwangzhe/satteri-mermaid";

mdastPlugins: [katex(), mermaidMdast()],
hastPlugins: [photoswipe(), mermaidHast()],

If you use createMermaidPlugin() + popFlags():

- import { createMermaidPlugin } from "@xingwangzhe/satteri-mermaid";
- const { plugin, popFlags } = createMermaidPlugin();
+ import { createMermaidMdastPlugin, createMermaidHastPlugin } from "@xingwangzhe/satteri-mermaid";
+ const { plugin: mdastPlugin, popFlags } = createMermaidMdastPlugin();
+ const { plugin: hastPlugin } = createMermaidHastPlugin();

Note: mermaid() and mermaidPlugin are still available as deprecated aliases. They only return the MDAST plugin and do not protect against Sätteri text transforms. Migrate to the dual-plugin approach for correct rendering.

Development

bun install
bun run dev     # vite dev server → http://localhost:5173 (example page)
bun run build   # vite build + tsc → dist/
bun run test    # vitest
bun run lint    # oxlint
bun run fmt     # oxfmt

License

MIT