Mermaid diagrams in Sphinx, powered by beautiful-mermaid
Project description
sphinx-oceanid
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
.mmdfiles instead of inline code - YAML frontmatter — Set title and per-diagram config via Mermaid frontmatter in
.mmdfiles 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de90f6fa90d649b7e024c8f55e5919396eb2f60135d3e948c27b86b3f01edb7a
|
|
| MD5 |
e43d8c6e59569fe62c35788262599111
|
|
| BLAKE2b-256 |
39bb4d3078c556ee6fd20b3d4df3d2e5f6d8d628969aeac2f8d3092530220cd4
|
Provenance
The following attestation bundles were made for sphinx_oceanid-0.2.0.tar.gz:
Publisher:
publish.yml on drillan/sphinx-oceanid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_oceanid-0.2.0.tar.gz -
Subject digest:
de90f6fa90d649b7e024c8f55e5919396eb2f60135d3e948c27b86b3f01edb7a - Sigstore transparency entry: 1399542262
- Sigstore integration time:
-
Permalink:
drillan/sphinx-oceanid@8ab810ce120eebedef9f1032e815e36a18ed9cd2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/drillan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ab810ce120eebedef9f1032e815e36a18ed9cd2 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b19c0de332bd0de27a9bfc0221667ffce5605fe4af4e44028cd94e461c48dff7
|
|
| MD5 |
5ee1a3fc9e894c6b4746d757f340f622
|
|
| BLAKE2b-256 |
cf934053b2aad76147da93d0910748379a108dbc098b90ddfef001c80b50ea39
|
Provenance
The following attestation bundles were made for sphinx_oceanid-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on drillan/sphinx-oceanid
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_oceanid-0.2.0-py3-none-any.whl -
Subject digest:
b19c0de332bd0de27a9bfc0221667ffce5605fe4af4e44028cd94e461c48dff7 - Sigstore transparency entry: 1399542315
- Sigstore integration time:
-
Permalink:
drillan/sphinx-oceanid@8ab810ce120eebedef9f1032e815e36a18ed9cd2 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/drillan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ab810ce120eebedef9f1032e815e36a18ed9cd2 -
Trigger Event:
push
-
Statement type: