Skip to content

Asciidoctor.js extension to convert diagrams to images using Kroki!

License

Notifications You must be signed in to change notification settings

danyill/asciidoctor-kroki

 
 

Repository files navigation

🖍 Asciidoctor Kroki Extension

Travis build status npm version

An extension for Asciidoctor.js to convert diagrams to images using Kroki!

Install

Node.js

Install the dependencies:

$ npm install asciidoctor asciidoctor-kroki

Create a file named kroki.js with following content and run it:

const asciidoctor = require('@asciidoctor/core')()
const kroki = require('asciidoctor-kroki')

const input = 'plantuml::hello.puml[svg,role=sequence]'

kroki.register(asciidoctor.Extensions)
console.log(asciidoctor.convert(input)) // <1>

const registry = asciidoctor.Extensions.create()
kroki.register(registry)
console.log(asciidoctor.convert(input, {'extension_registry': registry})) // <2>

<1> Register the extension in the global registry <2> Register the extension in a dedicated registry

Browser

Install the dependencies:

$ npm install asciidoctor asciidoctor-kroki

Create a file named kroki.html with the following content and open it in your browser:

<html>
  <head>
    <script src="node_modules/@asciidoctor/core/dist/browser/asciidoctor.js"></script>
    <script src="node_modules/asciidoctor-kroki/dist/browser/asciidoctor-kroki.js"></script>
  </head>
  <body>
    <div id="content"></div>
    <script>
      var input = 'plantuml::hello.puml[svg,role=sequence]'

      var asciidoctor = Asciidoctor()
      var kroki = AsciidoctorKroki

      const registry = asciidoctor.Extensions.create()
      kroki.register(registry)
      var result = asciidoctor.convert(input, {'extension_registry': registry})
      document.getElementById('content').innerHTML = result
    </script>
  </body>
</html>

<1> Register the extension in the global registry <2> Register the extension in a dedicated registry

Usage

[plantuml,alice-bob,svg,role=sequence]
....
alice -> bob
....

[graphviz]
....
digraph foo {
  node [style=rounded]
  node1 [shape=box]
  node2 [fillcolor=yellow, style="rounded,filled", shape=diamond]
  node3 [shape=record, label="{ a | b | c }"]

  node1 -> node2 -> node3
}
....

Contributing

Setup

To build this project, you will need Node.js >= 8.11 and npm (we recommend nvm to manage multiple active Node.js versions).

Building

  1. Install the dependencies:

    $ npm i

  2. Generate a distribution:

    $ npm run dist

When working on a new feature or when fixing a bug, make sure to run the linter and the tests suite:

$ npm run lint
$ npm run test

About

Asciidoctor.js extension to convert diagrams to images using Kroki!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 97.9%
  • HTML 1.6%
  • Shell 0.5%