3.0.1 • Published 10 months ago

remark-mermaid-dataurl v3.0.1

Weekly downloads
43
License
MIT
Repository
github
Last release
10 months ago

remark-mermaid-dataurl

npm version badge license badge node version support badge npm type definitions badge

A remark markdown plugin that renders mermaid markdown code into SVG data URLs using mermaid-cli.

Note:

This plugin is designed for Markdown to Markdown conversions, where keeping everything in a single file is required. The following plugins are more efficient in the majority of cases:

Example

Write your mermaid code in markdown using within code-blocks that start with ```mermaid, as in below:

Here is my **example** mermaid diagram in markdown:

```mermaid
stateDiagram-v2
    [*] --> Still
    Still --> [*]
    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> [*]
```

After running remark-mermaid-dataurl, the mermaid diagram within the ```mermaid code block will be rendered into an SVG file, then inserted into the markdown code as a dataurl (dataurl is truncated in the example, as they are quite large):

Here is my **example** mermaid diagram in markdown:

![Diagram generated via mermaid](data:image/svg+xml;charset=UTF-8,%3Csvg%20id%3D%22mermaid-1654...]

Options

const options = {
  mermaidCli: {
    // args to pass as `--arg value` to mermaidCli (run `npx mmdc --help` to view)
    // passing configFile or puppeteerConfigFile as an object will automatically be converted into a JSON
    configFile: {
      // see mermaid options at https://mermaid-js.github.io/mermaid/#/Setup
      theme: "forest",
    },
    puppeteerConfigFile: {
      // see options at https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#puppeteerlaunchoptions
      product: "firefox" // use firefox instead of chrome
      timeout: 60000, // change default puppeteer launch timeout
    },
  }
}

Usage with Docusaurus

see https://v2.docusaurus.io/docs/markdown-features#configuring-plugins for more info

First, install this plugin:

npm install --save remark-mermaid-dataurl

Then, add them to your @docusaurus/preset-classic options in docusaurus.config.js:

module.exports = {
  // ...
  presets: [
    [
      "@docusaurus/preset-classic",
      {
        docs: {
          // ...
          remarkPlugins: [
            require("remark-mermaid-dataurl"),
            // options, // optional options here
          ],
        },
      },
    ],
  ],
};

Afterwards, any ```markdown code blocks in your docusaurus docs folder should automatically be converted into SVGs data URLs when running npx docusaurus start or npx docusuarus serve.

3.0.1

10 months ago

3.0.0

10 months ago

2.1.1

2 years ago

2.0.7

2 years ago

2.1.0

2 years ago

2.0.5

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago