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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kevingimbel/eleventy-plugin-mermaid

v2.2.1

Published

Display graphs using the Mermaid JavaScript library

Downloads

1,283

Readme

eleventy-plugin-mermaid

Integrate Mermaid with eleventy

Usage

Install via npm:

npm install @kevingimbel/eleventy-plugin-mermaid

Include it in your .eleventy.js config file:

const pluginMermaid = require("@kevingimbel/eleventy-plugin-mermaid");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(pluginMermaid);
};

Add the JavaScript code to your page (before the closing body tag!)

{% mermaid_js %}
</body>
</html>

The {% mermaid_js %} code will render the following:

<script type="module">import mermaid from "${src}";mermaid.initialize({startOnLoad:true});</script>

${src}contains the script source as configured (see below). You can also skip this step and provide Mermaid as part of your JS bundle.

Config

Config Options

Global config options, set in eleventy.js.

| Option | Type | Default | Description | | ----------- | ---- | ------------- | ----------- | | mermaid_js_src | String | https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs | source from where Mermaid will be loaded | | html_tag | String | pre | The wrapping HTML tag which the graph is rendered inside | | extra_classes | String | "" | Extra CSS classes assigned to the wrapping element | | mermaid_config | String | {startOnLoad: true} | Define custom settings to be passed to mermaid.initialize |

Config Examples

const pluginMermaid = require("@kevingimbel/eleventy-plugin-mermaid");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(pluginMermaid, {
    // load mermaid from local assets directory
    mermaid_js_src: '/assets/mermaid.min.mjs',
    html_tag: 'div',
    extra_classes: 'graph',
    mermaid_config: {
      'startOnLoad': true,
      'theme': 'dark'
    }
  });
};

Inline configuration

It's possible to configure each graqph using mermaid's Inline configuration:

    ```mermaid
      %%{init: {'theme':'forest'}}%%
      graph TD
      A[Public web] -->|HTTP request| B(Firewall)
      B --> C{Is port open}
      C -->|Yes| D[App]
      C -->|No| E[Return error]
    ```

Examples

The plugin extends the 11ty markdown highlighter so mermaid diagrams can be written inline via code blocks marked with mermaid:

    ```mermaid
      graph TD;
      A[Want graphs in 11ty] -->|Search Plugin| B(Found plugin);
      B --> C{Use plugin?};
      C -->|Yes| D[NICE GRAPHS];
      C -->|No| E[NO GRAPHS];
    ```

Thanks

The code is mainly taken from https://cornishweb.com/index.php/2019/05/25/using-mermaid-js-with-eleventy-io/.

Future ideas

  • generate SVG server-side during build

Changelog

2.1.1

  • Fix closing pre tag in fallback output #5 by @BigBlueHat

2.1.0

  • Add document.addEventListener('DOMContentLoaded') around mermaidJS code
  • Add async tag to script
  • Pin mermaidJS version to 10 to avoid compatibility issues in the future. This can be overwritten by setting mermaid_js_src and only affects users who use {% mermaid_js %} shortcode.

2.0.0

MermaidJS switched to ESM only in version 10, which broke the old JavaScript path we used to get the script by default.

This version now uses the ESM module.