Skip to content

yousifalraheem/mermaid-parse

Repository files navigation

https://img.shields.io/npm/v/mermaid-parse Commitizen friendly semantic-release https://img.shields.io/github/languages/top/yousifalraheem/mermaid-parse https://img.shields.io/npm/l/mermaid-parse npm bundle size codecov

mermaid-parse

Parses Mermaid definitions into mermaid svg diagram.

Installation

Npm

npm i mermaid-parse

Yarn

yarn add mermaid-parse

Usage

import mermaidParse from 'mermaid-parse';

const definition = `
    graph TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F
`;

mermaidParse(definition, { extension: 'png' }).then(htmlRes => {
    res.send(htmlRes);
});

Configuration

Currently supported configurations:

option type description default
extension? "svg" | "png" The output extension svg

Documentation

This package uses Mermaid-js to transform the definition to svg diagram in HTML string format.

If you want to know how the definition is composed please read mermaid-js documentation.

This version does not support theming and other customization. Instead, it uses mermaid defaults. There are plans to support further configurations in the future.

The intended use for this package is to transform diagrams in node backend service and return it as a response.

License

MIT