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 🙏

© 2025 – Pkg Stats / Ryan Hefner

markdown-it-mermaid-server

v0.9.2

Published

A markdown-it plugin to render mermaid charts into SVG on the server

Readme

markdown-it-mermaid-server

A markdown-it plugin to transform textual Mermaid diagram definitions into SVG images.

markdown-it-mermaid-server runs on the server as part of the markdown-it transformation. The produced SVG images will be referenced in the Markdown-rendered HTML documents without the need of any Mermaid code running on the browser client. The plugin is perfectly suited for the build process of Static Site Generators (SSG), like for example 11ty.

In your Markdown, describe the Mermaid chart within a fenced codeblock, introduced with the mermaid keyword:

```mermaid
flowchart LR
A(["Start"]) --> B{"Decision"}
B --> C["Option A"] & D["Option B"]
```

and get the chart, wrapped into a figure tag:

<figure class="mermaid"><svg aria-roledescription="flowchart-v2" role="graphics-document document" viewBox="0 0 410.96875 174" id="mermaid-ttzhcnghnsgr"...></svg></figure>

Accessibility

To improve the accessibility of the resulting charts, the plugin allows to add a figcaption and alt text to every diagram definition, introduced by the keywords figcaption and alt. For example:

```mermaid
flowchart LR
figcaption This is the figcaption of the flow chart
alt This is the alt text of the flow chart
A(["Start"]) --> B{"Decision"}
B --> C["Option A"] & D["Option B"]
```

As result, you get:

<figure class="mermaid"><svg aria-label="This is the alt text of the flow chart" aria-roledescription="flowchart-v2" role="graphics-document document" viewBox="0 0 410.96875 174" id="mermaid-ttzhcnghnsgr"...></svg><figcaption>This is the figcaption of the flow chart</figcaption></figure>

The two properties are identified, interpreted and then removed by the plugin before handing over the chart definition to mermaid for chart generation, otherwise the chart rendering process would throw a syntax error. It does not matter in what line of the chart definition the properties are located. It´s only important that they have to stay in a single line each, and that the beginning of the line starts with either the keyword figcaption or alt.

Install

mermaid-cli-batch has a peer dependency to playwright that you have to install by yourself prior of using the package:

npm i playwright
npx playwright install chromium

Then install the package itself:

npm install markdown-it-mermaid-server

Use

import markdownItMermaidServer from 'markdown-it-mermaid-server'
import markdownIt from 'markdown-it'

const md = markdownIt()

//default settings
const markdownItMermaidOptions = {
  workingFolder: "mermaidTmp",
  clearWorkingFolder: false,
  throwOnError: false,
  verbose: false,
  useCache: true,
};

md.use(markdownItMermaidServer, markdownItMermaidOptions)

Options

Use the workingFolder exclusively for markdown-it-mermaid-server and not for other content. It also makes sense to have the folder part of your .gitignore file to avoid having the generated content being part of your code versioning.

  • workingFolder: A temporary folder to used to transform the Mermaid diagram definitions into SVG images. The default name of the folder is mermaidTmp. Add the folder to your .gitignore file, because it doesn´t require code versioning.
  • clearWorkingFolder: A value of true will delete the working folder when initializing the plugin. Default is false.
  • throwOnError: A value of true means errors are not catched and instead thrown. A value of false will catch and log errors. Default value is false.
  • verbose: A value of true will activate detailed logging. Default is false.
  • useCache: A value of true will activate the internal cache, which will render every chart only once with mermaid-cli and if the same chart (defined by its chart definition) is requested again, will use a cache to to render the inline svg. In local development scenarios this can save a lot of time for repeated builds. Default is true.