PlantUML Markdown Extension

3.11.1 · active · verified Sat Apr 11

plantuml-markdown is a Python-Markdown extension that enables embedding PlantUML diagrams directly into Markdown documents. It supports local PlantUML binary rendering, remote PlantUML servers, and Kroki servers. The current version is 3.11.1, with a regular release cadence addressing bug fixes and new features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to convert Markdown text containing PlantUML diagrams into HTML using `plantuml-markdown`. It shows both the GitHub-style triple-backtick syntax and the `::uml::` block syntax. The example configures a remote PlantUML server via the `servers` option, which is the recommended approach for versions 3.11.0 and later. For MkDocs, the plugin is enabled and configured in `mkdocs.yml`.

import markdown
import os

# For local rendering, ensure 'plantuml' command is in PATH and Java/Graphviz are installed.
# For remote rendering, use a server.
# This example uses a remote server for simplicity.
# In a real application, consider using os.environ for sensitive URLs or more robust configuration.
plantuml_server = os.environ.get('PLANTUML_SERVER_URL', 'http://www.plantuml.com/plantuml')

markdown_text = """
# My Document with a PlantUML Diagram

Here's a simple sequence diagram:

```plantuml format="svg"
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another action
```

And another one, using the alternative ::uml:: syntax:

::uml:: format="png"
Goofy -> MickeyMouse: calls
Goofy <-- MickeyMouse: responds
::end-uml::
"""

md = markdown.Markdown(extensions=['plantuml_markdown'], extension_configs={
    'plantuml_markdown': {
        'servers': [plantuml_server], # Using the new 'servers' config, introduced in 3.11.0
        'cachedir': 'plantuml_cache' # Optional: enable caching
    }
})

html_output = md.convert(markdown_text)
print(html_output)

# Example for MkDocs (mkdocs.yml)
# plugins:
#   - plantuml_markdown:
#       servers:
#         - http://www.plantuml.com/plantuml
#       cachedir: plantuml_cache

view raw JSON →