Skip to main content

Mermaid diagrams in Sphinx, powered by beautiful-mermaid

Project description

sphinx-oceanid

PyPI Python Documentation 日本語

Mermaid diagrams in Sphinx, powered by beautiful-mermaid.

Features

  • beautiful-mermaid rendering — Uses ELK.js-based layout engine for high-quality SVG output
  • CSS variable theming — Automatic dark/light theme detection with instant switching (no re-render)
  • Zero-config — Works out of the box with CDN-hosted beautiful-mermaid
  • sphinx-revealjs support — Lazy rendering for hidden slides via IntersectionObserver (example)
  • Pan & zoom — Native Pointer Events + SVG transform (no d3.js dependency)
  • Fullscreen modal — View diagrams in a viewport-sized overlay
  • External file support — Reference .mmd files instead of inline code
  • YAML frontmatter — Set title and per-diagram config via Mermaid frontmatter in .mmd files and RST
  • Auto class diagrams — Generate class hierarchy diagrams from Python code

Supported Diagram Types

Type Alias
flowchart graph
sequenceDiagram
classDiagram
stateDiagram stateDiagram-v2
erDiagram
xychart-beta

Unsupported diagram types produce explicit warnings (or errors), never silent degradation.

Installation

sphinx-oceanid requires Python 3.13+.

pip install sphinx-oceanid

From source:

pip install git+https://github.com/drillan/sphinx-oceanid.git

Or clone and install locally:

git clone https://github.com/drillan/sphinx-oceanid.git
cd sphinx-oceanid
pip install .

Quick Start

Add the extension to your conf.py:

extensions = ["sphinx_oceanid"]

Then use the mermaid directive in your reStructuredText files:

.. mermaid::

   flowchart LR
     A[Start] --> B[Process] --> C[End]

Or in Markdown (MyST) files:

```{mermaid}
sequenceDiagram
  Alice->>Bob: Hello
  Bob-->>Alice: Hi!
```

Build and preview — Mermaid diagrams require HTTP serving (file:// will not render due to CORS):

# Quick static server (no extra dependencies)
make -C docs serve

# Live reload (requires sphinx-autobuild)
pip install sphinx-oceanid[preview]
make -C docs livehtml

See docs/install.md for Makefile setup instructions.

Configuration

All configuration options use the oceanid_ prefix in conf.py:

# conf.py
extensions = ["sphinx_oceanid"]

# Theme (default: "auto" — detects dark/light from Sphinx theme)
oceanid_theme = "auto"
oceanid_theme_dark = "zinc-dark"
oceanid_theme_light = "zinc-light"

# Enable zoom on all diagrams (default: False)
oceanid_zoom = True

# Enable fullscreen modal (default: False)
oceanid_fullscreen = True

# Action for unsupported diagram types: "warning" or "error" (default: "warning")
oceanid_unsupported_action = "warning"

Directive Options

.. mermaid::
   :name: my-diagram
   :alt: Description for accessibility
   :align: center
   :caption: Diagram caption (rendered as <figcaption>)
   :title: Mermaid native title (rendered inside the diagram)
   :zoom:
   :config: {"theme": "forest"}

   flowchart LR
     A --> B --> C

YAML Frontmatter

External .mmd files can include YAML frontmatter to set the diagram title and per-diagram rendering options:

---
title: User Authentication Flow
config:
  bg: "#1a1b26"
  fg: "#a9b1d6"
---
flowchart TD
  A[Login Page] --> B{Valid credentials?}
  B -->|Yes| C[Dashboard]
  B -->|No| D[Error Message]

Frontmatter is also supported in RST inline content. In MyST Markdown, use directive options with JSON format for config. See the documentation for details.

Auto Class Diagrams

Generate class hierarchy diagrams from Python code:

.. autoclasstree:: mypackage.MyClass
   :full:
   :namespace: mypackage
   :caption: Class hierarchy

Documentation

Full documentation is available at drillan.github.io/sphinx-oceanid or in the docs/ directory.

License

BSD-3-Clause. See LICENSE for details.

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

sphinx_oceanid-0.1.2.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

sphinx_oceanid-0.1.2-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_oceanid-0.1.2.tar.gz.

File metadata

  • Download URL: sphinx_oceanid-0.1.2.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sphinx_oceanid-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0e442db1b5bdad0ce96cd52bd2aca072007591da085575f0ab85ba2103b33ab9
MD5 a619662a55d30702219bbbdb3ef236ae
BLAKE2b-256 8ca5dc1417d366e06bdff518f152f315c7007ce198ddd5c9028919291831621c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_oceanid-0.1.2.tar.gz:

Publisher: publish.yml on drillan/sphinx-oceanid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sphinx_oceanid-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sphinx_oceanid-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sphinx_oceanid-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 31e32b2db789a49a9b414796e788fb187234bfea9c55ea57ec306195dcbcb15b
MD5 0564e15fd790fdc1e1d47c29cea23018
BLAKE2b-256 33ba20b73b907faa1c97cadefff8709ca390acba6229421b58cfd67b205fc1f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_oceanid-0.1.2-py3-none-any.whl:

Publisher: publish.yml on drillan/sphinx-oceanid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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