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 .

Claude Code Skill (Optional)

This repository ships a mermaid-diagram skill for AI coding agents. It provides proactive diagram suggestions, syntax validation, and ready-made examples for all 6 supported diagram types.

Install it with gh skill install (preview, requires GitHub CLI 2.91+):

gh skill install drillan/sphinx-oceanid mermaid-diagram --agent claude-code

Supported --agent values: claude-code, github-copilot, cursor, codex, gemini, antigravity.

Use --scope user to install globally instead of per-project. See docs/install.md for details, version pinning, and update workflow.

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: True)
oceanid_zoom = False

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

# 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.2.0.tar.gz (19.9 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.2.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for sphinx_oceanid-0.2.0.tar.gz
Algorithm Hash digest
SHA256 de90f6fa90d649b7e024c8f55e5919396eb2f60135d3e948c27b86b3f01edb7a
MD5 e43d8c6e59569fe62c35788262599111
BLAKE2b-256 39bb4d3078c556ee6fd20b3d4df3d2e5f6d8d628969aeac2f8d3092530220cd4

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_oceanid-0.2.0.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.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for sphinx_oceanid-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b19c0de332bd0de27a9bfc0221667ffce5605fe4af4e44028cd94e461c48dff7
MD5 5ee1a3fc9e894c6b4746d757f340f622
BLAKE2b-256 cf934053b2aad76147da93d0910748379a108dbc098b90ddfef001c80b50ea39

See more details on using hashes here.

Provenance

The following attestation bundles were made for sphinx_oceanid-0.2.0-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