Kroki Macro

Last modified by Vincent Massol on 2025/03/31 00:12

cogCreate diagrams through the Kroki API which unifies several diagram generation libraries.
TypeXAR
CategoryMacro
Developed by

Apostu Daniel, Marius Dumitru Florea

Active Installs0
Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Success

Installable with the Extension Manager

Description

Create diagrams in multiple file formats (svg/jpeg/png/pdf/base64) based on a textual description with the help of the Kroki API.

Docker Prerequisites

Be aware that for the macro to be able to render diagrams the following are necessary:

  • Docker must be installed on the machine running XWiki.
  • the OS user running XWiki must be allowed to use / access the Docker engine.

Usage and Examples

Without a file format specified:

{{kroki diagramType="graphviz"}}
digraph G {Hello->World}
{{/kroki}}

graphviz.png
Simple diagram generated with the graphviz library

With a file format specified:

{{kroki diagramType="plantuml" outputType="png"}}
skinparam monochrome true
skinparam ranksep 20
skinparam dpi 150
skinparam arrowThickness 0.7
skinparam packageTitleAlignment left
skinparam usecaseBorderThickness 0.4
skinparam defaultFontSize 12
skinparam rectangleBorderThickness 1

rectangle "Main" {
  (main.view)
  (singleton)
}
rectangle "Base" {
  (base.component)
  (component)
  (model)
}
rectangle "<b>main.ts</b>" as main_ts

(component) ..> (base.component)
main_ts ==> (main.view)
(main.view) --> (component)
(main.view) ...> (singleton)
(singleton) ---> (model)
{{/kroki}}

plantuml.png
Diagram generated with the plantuml library

To create a diagram, you should now the syntax for the selected diagram type.

Refer to this diagram to see supported diagram types and output types.
diagramTypes.png
Types of diagrams and file types supported by Kroki

Parameters Definition

NameOptionalAllowed ValuesDefault ValueDescription
diagramTypeNotextThe service to be used to create the new diagram.
outputTypeYessvg, png, jpeg, pdf, base64svgThe file type of the new generated diagram.

Configuration

The Kroki Macro has a dedicated page in the Administration Section, which can be used to configure how the service works.

administrationPage.png
Kroki Configuration Section in Administration

There are 5 docker container configurations needed to support all diagram types offered by Kroki, which exist by default in the source code and they can be overwritten through the Kroki Configuration section in Administration by creating new configuration pages.
The Default container, which is used for the majority of diagram types by default has a configuration page.

defaultConfiguration.png
The configuration page of the Default configuration

The following are the properties of a configuration:

NameOptionalAllowed ValuesDefault ValueDescription
CONFIGURATION NAMENotextThe name of the configuration, can be used to overwrite properties through the xwiki.properties file.
DIAGRAM TYPESNoList of text values separated by ", "The diagram types for which this container is responsible.
DOCKER IMAGENotextThe name of the docker container image to be pulled from from Docker Hub.
CONTAINER NAMENotextThe name to be given to the docker container.
IS CONTAINER REUSABLENoyes or noNo if the macro should create a new container every time a request to the macro is made, yes if the container should be reused if it exists.
HOSTYesdomain of server hosting Kroki APIThe host to which Kroki API requests should be made, only if host is empty will the macro create a container and make requests to the container.
PORTYes, if host is provided16-bit positive numberThe port to which requests should be made, if the configuration has a valid host then port is optional, otherwise a port is required according to the docker image to be initialized.
HEALTH CHECK PATHYestextThe path to which a HTTP request should be made to check that the service is available(Ex:/graphviz/svg).
HEALTH CHECK BODYYestextThe body of the health check request.
HEALTH CHECK VERBNoan upper case HTTP verbThe HTTP action of the health check request, should be upper case(Ex:POST).
HEALTH CHECK ACCEPTED STATUS CODESNoone or multiple HTTP status codes, betweeen 200 and 206200 The HTTP response codes for which the service is considered available.

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes

v1.1

Dependencies

Dependencies for this extension (org.xwiki.contrib.kroki:macro-kroki-ui 1.1):

Get Connected