Skip to main content

MkDocs plugin for D2

Project description

mkdocs-d2-plugin

A plugin for the MkDocs documentation site generator which automatically generates and embeds D2 diagrams.

Requirements

Installation

Install the plugin using pip:

pip install mkdocs-d2-plugin

And add it to your mkdocs.yml:

plugins:
  - d2

Usage

The plugin will automatically generate and embed D2 diagrams from code blocks with the d2 language tag.

```d2
shape: sequence_diagram
Alice -> John: Hello John, how are you?
Alice -> John.ack: John, can you hear me?
John.ack -> Alice: Hi Alice, I can hear you!
John -> Alice: I feel great!
```

Configuration

The plugin can be configured in your mkdocs.yml file.

plugins:
  - d2:
      executable: d2
      layout: dagre
      theme: 0
      dark_theme: False
      sketch: False
      pad: 100
      scale: -1.0
      force_appendix: False

Run d2 --help for more information about the options.

Everything (except executable path) can be overriden locally.

```d2 sketch=true force_appendix=True
shape: sequence_diagram
Alice -> John: Hello John, how are you?
Alice -> John.ack: John, can you hear me?
John.ack -> Alice: Hi Alice, I can hear you!
John -> Alice: I feel great!
```

List of available themes

Example

You can find example app in the example directory. Live version is available here.

To run in locally:

cd example
python3 -m venv .venv
source .venv/bin/activate
pip install mkdocs-material mkdocs-d2-plugin
mkdocs serve

To run it using Docker:

cd example
docker build --tag mkdocs-d2-plugin:latest .
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs mkdocs-d2-plugin:latest

<rant>

Why this fenced code block format?

```d2 key=value
[...]
```

MkDocs uses python-markdown library, which expects key-value pairs in a following format:

```{ .d2 key="value" }
[...]
```

This breaks syntax highlighting in most editors. The format used by this plugin breaks python-markdown library instead, however the entire code block is replaced anyway, so it doesn't matter. And according to CommonMark specification it is a valid Markdown.

</rant>

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

mkdocs-d2-plugin-0.2.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_d2_plugin-0.2.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-d2-plugin-0.2.2.tar.gz.

File metadata

  • Download URL: mkdocs-d2-plugin-0.2.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for mkdocs-d2-plugin-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d328b35f65fb202efb618adf684503b2100d7ac44ea6945e1a2f179225400c0e
MD5 494a3877a175b1c9332703acfc5806bf
BLAKE2b-256 16e1cbb813fb23330fbab010361e7b6f6d2f0aee945121350d9b2fe7626dffd7

See more details on using hashes here.

File details

Details for the file mkdocs_d2_plugin-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_d2_plugin-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0139b0cc066fe23ccf3e6cc4f1a1b2a75efb3be398f221f4250e6da715dcdb22
MD5 8e67e48b6cfed0683a61c4adca02dfeb
BLAKE2b-256 aa1a92dfad3d52c6a016f404da3a7ce22b9cc6a3741e023b59710ed8fe9cfc5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page