0.1.1 • Published 3 years ago

remark-kroki-plugin v0.1.1

Weekly downloads
13
License
Apache 2.0
Repository
github
Last release
3 years ago

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.

0.1.0

3 years ago

0.1.1

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago