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

remark-kroki-plugin

v0.1.1

Published

Generate images from text using the kroki web service

Downloads

602

Readme

Remark Kroki Plugin

Kroki provides a web service that can be used to generate images from a wide range of supported DSL's, for example mermaid, PlantUML, GraphViz and many others.

This plugin allows the user to provide th DSL for an image in one of the kroki supported dialects within a code block. The remark processor will replace the image code block with the generated image.

Installation

The include code plugin is normally used in the context of a site generator using the remark markdown processor underneath. For example, to use the plugin within Docusaurus 2,

  1. Include remark-kroki-plugin": "0.1.0" in the package.json of the docusaurus website project.

  2. Within docusaurus.config.js, configure the plugin with the following parameters:

    1. krokiBase: The base URL of the kroki web service. This is usually https://kroki.io unless e selfhosted kroki instance shall be used.
    2. lang: The image transformations is applied for all codeblocks with this language.
    3. imgRefDir: The prefix that will be used for a generated image to create the link.
    4. imgDir: The directory where the generated image files are stored.

Docusaurus 2

Within Docusaurus 2 the plugin could be configured as below:

  presets: [
    [
      '@docusaurus/preset-classic',
      {
        docs: {
          sidebarPath: require.resolve('./sidebars.js'),
          remarkPlugins: [
            [require('remark-kroki-plugin'), { krokiBase: 'https://kroki.io', lang: "kroki", imgRefDir: "../img/kroki", imgDir: "static/img/kroki" }]
          ],
        },
        blog: {
          showReadingTime: false,
          remarkPlugins: [
            [require('remark-kroki-plugin'), { krokiBase: 'https://kroki.io', lang: "kroki", imgRefDir: "../img/kroki", imgDir: "static/img/kroki" }]
          ],
        },
        theme: {
          customCss: [
            require.resolve('./src/css/custom.css'),
            //require.resolve('./node_modules/prism-themes/themes/prism-cb.css')
          ],
        },
      },
    ],
  ]

Usage

The image generator will be triggered by a code block that uses the configured language within it's language parameter. The plugin will use the imgType attribute to determine which generator shall be used within the kroki web service.

The generator will POST the content of the code block to the kroki web service and either report an error or generate an appropriate SVG file in the imgDir.

The filename of the generated image will is generated as $(MD5 hash of the image code).svg. When the file with the calculated filename already exists within the image directory, this will be used as the image file, otherwise the kroki web service will be called to generate the file.

The user can decide to put generated images under version control so that images generated once can be reused until the text changes.

Examples

Generate a mermaid image

Development

It might be good to allow the generated filename to be overwritten with a parameter.

The code has been realized in typescript follwing this excellent tutorial ff.