Diagram extension for Python-Markdown using Kroki server.
Project description
markdown-kroki
Diagram extension for Python-Markdown using Kroki server.
This extension converts various diagram code blocks into Base64 encoded data: URI. This enables PDF generation with tools like MkDocs to PDF/WeasyPrint without requiring JavaScript, even during web browsing.
Install
pip install markdown-kroki
Requirements
Internet access to the public Kroki server
Default setting with no options.
Self-Managed Kroki server (recommended)
Here is a sample Docker Compose file.
ref. Kroki.io > Install > Using Docker or Podman
docker compose up -d
The default port used by MkDocs (
mkdocs serve) may conflict with the default port of a Dockerized Kroki instance. Consequently, you will need to change the port configuration for one of them.
Usage
```{diagram language} formant=[svg|png] {img tag attribute}="value" {diagram option}="value"
```
MkDocs Integration
# mkdocs.yml
markdown_extensions:
- markdown_kroki:
kroki_url: http://localhost:18000 # default: https://kroki.io
Python code
import markdown
from markdown_kroki import KrokiDiagramExtension
markdown_text = """```plantuml format="svg" theme="sketchy-outline" width="300"
@startuml
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
@enduml
```"""
html_output = markdown.markdown(markdown_text, extensions=[
KrokiDiagramExtension(kroki_url='https://kroki.io')])
print(html_output)
<p><img src="data:image/svg+xml;base64,PHN2ZyBhcmlhLXJvbGVkZXNjcmlwdGlvbj0ic2VxdWVuY2UiIHJvbGU
9ImdyYXBoaWNzLWRvY3VtZW50IGRvY3VtZW50IiB2aWV3Qm94PSItNTAgLTEwIDc1MCA1NzQiIHN0eWxlPSJtYXgtd2lkd
Gg6IDc1MHB4OyBiYWNrZ3JvdW5kLWNvbG9yOiB3aGl0ZTsiIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk
...
...
...
IHgxPSIyNzYiLz48L3N2Zz4=" width="300" ></p>
Process flow
sequenceDiagram
participant application as Application<br/>(eg MkDocs)
participant markdown as Python Markdown
participant extension as KrokiDiagramExtension
participant engine as Kroki Server
application->>markdown: Markdown + Diagrams
markdown->>extension: Preprocessor
extension->>engine: Diagram code
engine-->>engine: Convert
engine-->>extension: Image Data
extension-->>extension: Base64 encode
extension-->>markdown: Markdown + data URI image
markdown-->>application: HTML + data URI image
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file markdown_kroki-0.2.0.tar.gz.
File metadata
- Download URL: markdown_kroki-0.2.0.tar.gz
- Upload date:
- Size: 78.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b087a8acfd86bed34266409a2f5c86ecaf67ca89d302f362e9b7be06452aaad
|
|
| MD5 |
cc912ec612ef8924570c29f8dd92bedf
|
|
| BLAKE2b-256 |
44a2efdeb51c41817762dc27e22129a4f1dd2ce3ee0bb5c612ecff2088f18ef4
|
Provenance
The following attestation bundles were made for markdown_kroki-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on hkato/markdown-kroki
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_kroki-0.2.0.tar.gz -
Subject digest:
9b087a8acfd86bed34266409a2f5c86ecaf67ca89d302f362e9b7be06452aaad - Sigstore transparency entry: 200667330
- Sigstore integration time:
-
Permalink:
hkato/markdown-kroki@aa39c33f70fc613e73df95464d8d7f405b55dae0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/hkato
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@aa39c33f70fc613e73df95464d8d7f405b55dae0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file markdown_kroki-0.2.0-py3-none-any.whl.
File metadata
- Download URL: markdown_kroki-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ef648f84f6aab7eddd06a09100b250e14182c1e5211b60790c0017846c8b7d2
|
|
| MD5 |
f2fe24b544156d70972410fe00745be2
|
|
| BLAKE2b-256 |
5925e1bb68d339e5872b682588e4d0a9eb15334477f1fb7db3644353f3d8ec89
|
Provenance
The following attestation bundles were made for markdown_kroki-0.2.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on hkato/markdown-kroki
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
markdown_kroki-0.2.0-py3-none-any.whl -
Subject digest:
0ef648f84f6aab7eddd06a09100b250e14182c1e5211b60790c0017846c8b7d2 - Sigstore transparency entry: 200667335
- Sigstore integration time:
-
Permalink:
hkato/markdown-kroki@aa39c33f70fc613e73df95464d8d7f405b55dae0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/hkato
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@aa39c33f70fc613e73df95464d8d7f405b55dae0 -
Trigger Event:
push
-
Statement type: