API
Public
Kroki.Kroki — ModuleThe main Module containing the necessary types of functions for integration with a Kroki service.
Defines Base.show and corresponding Base.showable methods for different output formats and Diagram types, so they render in their most optimal form in different environments (e.g. the documentation system, Documenter output, Pluto, Jupyter, etc.).
Kroki.Diagram — Typestruct DiagramA representation of a diagram that can be rendered by a Kroki service.
Examples
julia> Kroki.Diagram(:PlantUML, "Kroki -> Julia: Hello Julia!")
┌─────┐ ┌─────┐
│Kroki│ │Julia│
└──┬──┘ └──┬──┘
│ Hello Julia! │
│───────────────>│
┌──┴──┐ ┌──┴──┐
│Kroki│ │Julia│
└─────┘ └─────┘Fields
options::Dict{String, String}Options to modify the appearance of the
specificationwhen rendered.Valid options depend on the
typeof diagram. See Kroki's website for details.The keys are case-insensitive. All specified options are passed through to Kroki, which ignores unkown options.
specification::AbstractStringThe textual specification of the diagram.
type::SymbolThe type of diagram specification (e.g. ditaa, Mermaid, PlantUML, etc.). This value is case-insensitive.
Kroki.Diagram — MethodDiagram(type::Symbol, specification::AbstractString; kwargs...) -> Diagram
Constructs a Diagram from the specification for a specific type of diagram.
Passes keyword arguments through to Diagram untouched.
Kroki.Diagram — MethodDiagram(type::Symbol; path, specification, kwargs...)
Constructs a Diagram from the specification for a specific type of diagram, or loads the specification from the provided path.
Specifying both keyword arguments, or neither, is invalid.
Passes any further keyword arguments through to Diagram untouched.
Kroki.SUPPORTED_TEXT_PLAIN_SHOW_MIME_TYPES — ConstantThe values that can be used to configure TEXT_PLAIN_SHOW_MIME_TYPE:
text/plain; charset=utf-8text/plain
Kroki.TEXT_PLAIN_SHOW_MIME_TYPE — ConstantDefines the MIME type to be used when show gets called on a Diagram for the text/plain MIME type.
Should be set to a variation of the text/plain MIME type. For instance, text/plain; charset=utf-8 to enable Unicode rendering for certain diagrams, e.g. PlantUML and Structurizr.
Only a select number of variations are supported, see LIMITED_DIAGRAM_SUPPORT and SUPPORTED_TEXT_PLAIN_SHOW_MIME_TYPES for details.
Defaults to text/plain; charset=utf-8.
Kroki.render — Functionrender(diagram::Diagram, output_format::AbstractString; options) -> Vector{UInt8}
Renders a Diagram through a Kroki service to the specified output format.
Allows the specification of diagram options through the options keyword. The options default to those specified on the Diagram.
If the Kroki service responds with an error, throws an InvalidDiagramSpecificationError or InvalidOutputFormatError if a known type of error occurs. Other errors (e.g. HTTP.ExceptionRequest.StatusError for connection errors) are propagated if they occur.
SVG output is supported for all Diagram types. See the support table for an overview of other supported output formats per diagram type.
Service Management
Kroki.Service — ModuleDefines functions and constants managing the Kroki service the rest of the package uses to render diagrams. These services can be either local or remote.
This module also enables management of a local service instance, provided Docker and Docker Compose are available on the system.
Exports
Imports
BaseCoreDocStringExtensionsKroki.Documentation
Kroki.Service.DockerComposeExecutionError — Typestruct DockerComposeExecutionError <: ExceptionA specialized Exception to include reporting instructions for specific types of errors that may occur while trying to execute docker-compose.
Fields
message::String
Kroki.Service.info — Methodinfo() -> Markdown.MD
Provides an overview of the (versions of) tools supporting the different diagram types based on information provided by the service as configured through setEndpoint!.
Example
julia> Kroki.Service.info()
The active Kroki service (https://kroki.io) runs v0.17.2 (705d6f7), which is configured with the following diagram type versions.
| Diagram Type | Version |
|---|---|
| BPMN | 9.0.3 |
| Byte Field | 1.6.1 |
| C4 with PlantUML | 1.2022.5 |
| Excalidraw | 0.1.2 |
| Graphviz | 2.40.1 |
| Mermaid | 9.1.1 |
| Pikchr | 7269f78c4a |
| PlantUML | 1.2022.5 |
| Structurizr | 1.19.1 |
| Svgbob | 0.5.3 |
| UMLet | 14.3.0 |
| Vega-Lite | 5.2.0 |
| Vega | 5.22.0 |
| WaveDrom | 2.9.1 |
| actdiag | 3.0.0 |
| blockdiag | 3.0.0 |
| diagrams.net | 16.2.4 |
| ditaa | 1.3.13 |
| erd | 0.2.1.0 |
| nomnoml | 1.5.1 |
| nwdiag | 3.0.0 |
| packetdiag | 3.0.0 |
| rackdiag | 3.0.0 |
| seqdiag | 3.0.0 |
The presence of a diagram type in this list does not mean it is actually supported by the service at https://kroki.io. This is due to some diagram types requiring additional services that may not be available, as they need to be managed separately. See the architecture section on Kroki's website for more information.
Kroki.Service.setEndpoint! — FunctionsetEndpoint!() -> String
setEndpoint!(endpoint::AbstractString) -> String
Sets the ENDPOINT using a fallback mechanism if no endpoint is provided.
The fallback mechanism checks for a KROKI_ENDPOINT environment variable specifying an endpoint (e.g. to be used across Julia instances). If this environment variable is also not present the DEFAULT_ENDPOINT is used.
This can, for instance, be used in cases where a privately hosted instance is available or when a local service has been start!ed.
Returns the value that ENDPOINT got set to.
Examples
setEndpoint!()setEndpoint!("http://localhost:8000")
Kroki.Service.start! — Functionstart!()
start!(update_endpoint::Bool)
Starts the Kroki service components on the local system, optionally, ensuring ENDPOINT points to them.
Pass false to the function to prevent the ENDPOINT from being updated. The default behavior is to update.
Kroki.Service.status — Methodstatus() -> Any
Returns a NamedTuple where the keys are the names of the service components and the values their corresponding 'running' state.
Examples
julia> status()
(core = true, mermaid = false)Kroki.Service.stop! — Functionstop!()
stop!(perform_cleanup::Bool)
Stops any running Kroki service components ensuring ENDPOINT no longer points to the stopped service.
Cleans up left-over containers by default. This behavior can be turned off by passing false to the function.
Kroki.Service.update! — Methodupdate!()
Updates the Docker images for the individual Kroki service components.
String Literals
The following string literals are exported from the Kroki module to make it more straightforward to instantiate Diagrams.
Kroki.StringLiterals — ModuleDefines string literals for all supported Diagram types, making it more straightforward to write diagrams inline.
Exports
@actdiag_str@blockdiag_str@bpmn_str@bytefield_str@c4plantuml_str@diagramsnet_str@ditaa_str@erd_str@excalidraw_str@graphviz_str@mermaid_str@nomnoml_str@nwdiag_str@packetdiag_str@pikchr_str@plantuml_str@rackdiag_str@seqdiag_str@structurizr_str@svgbob_str@umlet_str@vega_str@vegalite_str@wavedrom_str
Imports
BaseCoreDocStringExtensionsKroki.Documentation
Kroki.StringLiterals.@actdiag_str — MacroKroki.StringLiterals.@blockdiag_str — MacroKroki.StringLiterals.@bpmn_str — MacroKroki.StringLiterals.@bytefield_str — MacroString literal for instantiating Byte Field Diagrams.
Kroki.StringLiterals.@c4plantuml_str — MacroString literal for instantiating C4 with PlantUML Diagrams.
Kroki.StringLiterals.@diagramsnet_str — MacroString literal for instantiating diagrams.net Diagrams.
Kroki.StringLiterals.@ditaa_str — MacroKroki.StringLiterals.@erd_str — MacroKroki.StringLiterals.@excalidraw_str — MacroString literal for instantiating Excalidraw Diagrams.
Kroki.StringLiterals.@graphviz_str — MacroKroki.StringLiterals.@mermaid_str — MacroKroki.StringLiterals.@nomnoml_str — MacroKroki.StringLiterals.@nwdiag_str — MacroKroki.StringLiterals.@packetdiag_str — MacroString literal for instantiating packetdiag Diagrams.
Kroki.StringLiterals.@pikchr_str — MacroKroki.StringLiterals.@plantuml_str — MacroKroki.StringLiterals.@rackdiag_str — MacroKroki.StringLiterals.@seqdiag_str — MacroKroki.StringLiterals.@structurizr_str — MacroString literal for instantiating Structurizr Diagrams.
Kroki.StringLiterals.@svgbob_str — MacroKroki.StringLiterals.@umlet_str — MacroKroki.StringLiterals.@vega_str — MacroKroki.StringLiterals.@vegalite_str — MacroKroki.StringLiterals.@wavedrom_str — MacroPrivate
Kroki.DiagramTypeMetadata — Typestruct DiagramTypeMetadataA container to associate metadata with a specific diagram type, e.g. for documentation purposes.
Fields
name::StringA more readable name for the diagram type, if applicable.
url::StringThe URL to the website/documentation of the diagram type.
Kroki.DIAGRAM_TYPE_METADATA — ConstantAn overview of metadata for the different Diagram types that can be rendered, e.g. links to the main documentation, friendly names, etc.
Kroki.LIMITED_DIAGRAM_SUPPORT — ConstantSome MIME types are not supported by all diagram types, this constant contains all these limitations. The union of all values corresponds to all supported Diagram types.
Note that SVG output is supported by all diagram types, as is reflected in the support matrix below. Only those diagram types that explicitly only support SVG output are included in this constant.
Those diagram types that support plain text output, i.e. not just rendering their specification, support both ASCII and Unicode character sets for rendering. This is expressed using two different text/plain MIME types. See also SUPPORTED_TEXT_PLAIN_SHOW_MIME_TYPES.
Support Matrix
application/pdf | image/jpeg | image/png | image/svg+xml | text/plain | text/plain; charset=utf-8 | |
|---|---|---|---|---|---|---|
| actdiag | ✅ | ✅ | ✅ | |||
| blockdiag | ✅ | ✅ | ✅ | |||
| BPMN | ✅ | |||||
| Byte Field | ✅ | |||||
| C4 with PlantUML | ✅ | ✅ | ✅ | ✅ | ✅ | |
| diagrams.net | ✅ | ✅ | ||||
| ditaa | ✅ | ✅ | ||||
| erd | ✅ | ✅ | ✅ | ✅ | ||
| Excalidraw | ✅ | |||||
| Graphviz | ✅ | ✅ | ✅ | ✅ | ||
| Mermaid | ✅ | ✅ | ||||
| nomnoml | ✅ | |||||
| nwdiag | ✅ | ✅ | ✅ | |||
| packetdiag | ✅ | ✅ | ✅ | |||
| Pikchr | ✅ | |||||
| PlantUML | ✅ | ✅ | ✅ | ✅ | ✅ | |
| rackdiag | ✅ | ✅ | ✅ | |||
| seqdiag | ✅ | ✅ | ✅ | |||
| Structurizr | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Svgbob | ✅ | |||||
| UMLet | ✅ | ✅ | ✅ | |||
| Vega | ✅ | ✅ | ✅ | |||
| Vega-Lite | ✅ | ✅ | ✅ | |||
| WaveDrom | ✅ |
Kroki.MIME_TO_RENDER_ARGUMENT_MAP — ConstantMaps MIME types to the arguments that have to be passed to the render function, which are in turned passed to the Kroki service.
Kroki.UriSafeBase64Payload — FunctionUriSafeBase64Payload(diagram::Diagram) -> String
Compresses a Diagram's specification using zlib, turning the resulting bytes into a URL-safe Base64 encoded payload (i.e. replacing + by - and / by _) to be used in communication with a Kroki service.
See the Kroki documentation for more information.
Kroki.getDiagramTypeMetadata — FunctiongetDiagramTypeMetadata(diagram_type::Symbol) -> Kroki.DiagramTypeMetadata
Retrieves the metadata for a given diagram_type from DIAGRAM_TYPE_METADATA, with a fallback to a generic DiagramTypeMetadata.
Documentation
Kroki.Documentation — ModuleContains templates and a helper macro @setupDocstringMarkup to easily set up consistent docstring formats across modules.
Kroki.Documentation.@setupDocstringMarkup — MacroHelper macro ensuring consistent docstring markup across modules through templating.
Exceptions
Kroki.Exceptions — ModuleDefines all custom Exceptions that can be thrown by different parts of the package along with their corresponding Base.showerror overloads.
Exports
Imports
BaseCoreDocStringExtensionsKroki.Documentation
Kroki.Exceptions.DiagramPathOrSpecificationError — Typestruct DiagramPathOrSpecificationError <: ExceptionAn Exception to be thrown when the path and specification keyword arguments to Diagram are not specified mutually exclusive.
Fields
Kroki.Exceptions.InfoRetrievalError — Typestruct InfoRetrievalError <: ExceptionAn Exception to be thrown when Kroki.Service.info cannot retrieve its information from the Kroki service configured through Kroki.Service.setEndpoint!.
Fields
endpoint::StringThe endpoint that was queried for information about a Kroki service.
Kroki.Exceptions.InvalidDiagramSpecificationError — Typestruct InvalidDiagramSpecificationError <: ExceptionAn Exception to be thrown when a Diagram representing an invalid specification is passed to render.
Fields
error::StringThe error message returned by the Kroki service causing the exception to be thrown.
cause::DiagramThe
Diagramthat caused the error.
Kroki.Exceptions.InvalidOutputFormatError — Typestruct InvalidOutputFormatError <: ExceptionAn Exception to be thrown when a Diagram is rendered to an unsupported or invalid output format.
Fields
error::StringThe error message returned by the Kroki service causing the exception to be thrown.
cause::DiagramThe
Diagramthat caused the error.
Kroki.Exceptions.UnsupportedMIMETypeError — Typestruct UnsupportedMIMETypeError <: ExceptionAn Exception to be thrown when the selected_mime_type is not an element of the set of supported_mime_types.
Fields
selected_mime_type::MIMEThe selected
MIMEtype that is not supported.supported_mime_types::Set{MIME}The set of supported
MIMEtypes.
Service Management
Kroki.Service.DEFAULT_ENDPOINT — ConstantThe default ENDPOINT to use, i.e. the publicly hosted version.
Kroki.Service.ENDPOINT — ConstantThe currently active Kroki service endpoint being used.
Kroki.Service.SERVICE_DEFINITION_FILE — ConstantPath to the Docker Compose definitions for running a local Kroki service.
Kroki.Service.executeDockerCompose — FunctionexecuteDockerCompose(cmd::Vector{String}) -> String
Helper function for executing Docker Compose commands.
Returns captured stdout.
Throws an ErrorException if Docker and/or Docker Compose aren't available. Throws a DockerComposeExecutionError if any other exception occurs during execution.
String Literals
Kroki.StringLiterals.interpolate — Methodinterpolate(specification::AbstractString) -> Vector{Expr}
Helper function implementing string interpolation to be used in conjunction with macros defining diagram specification string literals, as they do not support string interpolation by default.
Returns an array of elements, e.g. Expressions, Symbols, Strings that can be incorporated in the args of another Expression.
Kroki.StringLiterals.shouldInterpolate — MethodshouldInterpolate(stream::IO) -> Bool
When called at the start of an expression to interpolate, checks whether the interpolation sign that triggered interpolation was escaped or not. This takes into account multiple escaped escape characters in front of an interpolation sign.