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

mermaid-isomorphic

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mermaid-isomorphic

Transform mermaid diagrams in the browser or Node.js

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mermaid-isomorphic

github actions npm codecov

Render Mermaid diagrams in the browser or Node.js.

This is useful if you wish to render Mermaid diagrams in a Node.js or an isomorphic environment. If you want to render Mermaid diagrams in the browser directly, use the mermaid package directly.

Table of Contents

Installation

npm install mermaid-isomorphic

This library uses Playwright under the hood in Node.js. You may need to install the Playwright browser before using this package.

npx playwright install --with-deps chromium

Usage

First, create a Mermaid renderer. Then use this renderer to render your diagrams.

import { createMermaidRenderer } from 'mermaid-isomorphic'

const renderer = createMermaidRenderer()
const diagram = `
graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;
`

const results = await renderer([diagram])
console.log(results)

Fonts

FontAwesome

Mermaid has support for FontAwesome. This is also supported by isomorphic-mermaid, but you need to load the FontAwesome CSS yourself when serving the SVG.

Custom Fonts

By default mermaid-isomorphic uses the arial,sans-serif font family. This font family is mostly compatible across all browsers and devices. If you wish to use a custom font, you need to specify both the mermaidConfig.fontFamily and css options.

Browser

mermaid-isomorphic is intended for use in Node.js, but also provides a browser export. This means it can be used in the browser, but it’s recommended to use the mermaid package directly.

API

createMermaidRenderer(options?: CreateMermaidRendererOptions)

Create a Mermaid renderer.

The Mermaid renderer manages a browser instance. If multiple diagrams are being rendered simultaneously, the internal browser instance will be re-used. If no diagrams are being rendered, the browser will be closed.

Options
  • browser (BrowserType): The Playwright browser to use. (default: chromium)
  • launchOptions: (LaunchOptions): The options used to launch the browser.
Returns

A function that renders Mermaid diagrams in the browser. This function has arguments:

  • diagrams (string[]): An array of mermaid diagrams to render.
  • options:
    • css (string | URL) A URL that points to a custom CSS file to load. Use this to load custom fonts. This option is ignored in the browser. You need to include the CSS in your build manually.
    • format (png | svg): Whether to return the rendered diagram as an SVG string or a PNG buffer. PNG is only supported in Node.js.
    • prefix (string): A custom prefix to use for Mermaid IDs (default: mermaid).
    • mermaidOptions (MermaidConfig): A custom Mermaid configuration. By default fontFamily is set to arial,sans-serif. This option is ignored in the browser. You need to call mermaid.initialize() manually.

It returns a promise settled result with the rendered diagrams as a string or buffer depending on the format.

Contributing

Test fixtures are generated and verified using Linux. Rendering on other platforms may yield slightly different results. Don’t worry about adding new fixtures, but don’t update existing ones that cause CI to fail. Furthermore see my global contributing guidelines.

License

MIT @ Remco Haszing

Keywords

FAQs

Package last updated on 29 Apr 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