Skip to content

Commit 1f1d455

Browse files
committed
docs: add mermaid extension
1 parent f566acd commit 1f1d455

File tree

5 files changed

+95
-1
lines changed

5 files changed

+95
-1
lines changed

docs/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727
"nbsphinx",
2828
"numpydoc",
2929
"sphinx_sitemap",
30+
"sphinxcontrib.mermaid",
3031
]
3132
todo_include_todos = True
3233
autosummary_generate = True
3334
jupyter_sphinx_thebelab_config = {
3435
'requestKernel': True,
3536
}
37+
jupyter_sphinx_require_url = ''
38+
nbsphinx_requirejs_path = ''
3639

3740
extlinks = {
3841
'pull': ('https://github.com/lepture/shibuya/pull/%s', 'pull request #%s'),

docs/contributing/roadmap.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ These good things will be added in the future:
2323
- :bdg-success:`DONE` Perfect code highlight style
2424
- :bdg-success:`DONE` Edit this page link
2525
- :bdg-success:`DONE` GitHub stars and forks
26-
- :bdg-warning:`TODO` Scroll to top
26+
- :bdg-success:`DONE` Back to top
2727
- :bdg-success:`DONE` Breadcrumbs
2828

2929
Design for other extensions
@@ -39,6 +39,7 @@ Make sure it works well with other extensions. Currently integrated with:
3939
- :bdg-success:`DONE` :ref:`nbsphinx`
4040
- :bdg-success:`DONE` :ref:`numpydoc`
4141
- :bdg-success:`DONE` ``sphinx-gallery``
42+
- :bdg-success:`DONE` :ref:`sphinxcontrib-mermaid`
4243

4344
Instant search
4445
--------------

docs/extensions/mermaid.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
:description: Embed Mermaid flowcharts, sequence diagrams, gantt diagrams and more in your documents with Shibuya theme.
2+
3+
.. _sphinxcontrib-mermaid:
4+
5+
sphinxcontrib-mermaid
6+
=====================
7+
8+
This extension allows you to embed Mermaid graphs in your documents,
9+
including general flowcharts, sequence diagrams, gantt diagrams and more.
10+
11+
**Documentation**: https://sphinxcontrib-mermaid-demo.readthedocs.io/
12+
13+
Install
14+
-------
15+
16+
.. code-block:: bash
17+
18+
pip install sphinxcontrib-mermaid
19+
20+
Then, add the extension to your ``conf.py``:
21+
22+
.. code-block:: python
23+
:caption: conf.py
24+
25+
extensions = [
26+
# ...
27+
"sphinxcontrib.mermaid",
28+
]
29+
30+
Usage
31+
-----
32+
33+
It adds a ``mermaid`` directive to embed mermaid markup. For example:
34+
35+
.. code-block:: none
36+
37+
.. mermaid::
38+
39+
sequenceDiagram
40+
participant Alice
41+
participant Bob
42+
Alice->John: Hello John, how are you?
43+
loop Healthcheck
44+
John->John: Fight against hypochondria
45+
end
46+
Note right of John: Rational thoughts <br/>prevail...
47+
John-->Alice: Great!
48+
John->Bob: How about you?
49+
Bob-->John: Jolly good!
50+
51+
.. mermaid::
52+
53+
sequenceDiagram
54+
participant Alice
55+
participant Bob
56+
Alice->John: Hello John, how are you?
57+
loop Healthcheck
58+
John->John: Fight against hypochondria
59+
end
60+
Note right of John: Rational thoughts <br/>prevail...
61+
John-->Alice: Great!
62+
John->Bob: How about you?
63+
Bob-->John: Jolly good!
64+
65+
Mermaid not working
66+
-------------------
67+
68+
You may encounter an error of::
69+
70+
Uncaught ReferenceError: mermaid is not defined
71+
72+
Here are some possible fixes:
73+
74+
1. There will be a ``requirejs`` conflict with :ref:`nbsphinx` extension,
75+
you can use ``nbsphinx_requirejs_path`` setting to resolve the issue:
76+
77+
.. code-block:: python
78+
:caption: conf.py
79+
80+
nbsphinx_requirejs_path = ''
81+
82+
2. Mermaid extension is conflict with :ref:`sphinx-jupyter` too, you can
83+
resolve the issue with ``jupyter_sphinx_require_url`` setting:
84+
85+
.. code-block:: python
86+
:caption: conf.py
87+
88+
jupyter_sphinx_require_url = ''

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Shibuya
7474
extensions/jupyter-sphinx
7575
extensions/nbsphinx
7676
extensions/numpydoc
77+
extensions/mermaid
7778

7879
.. toctree::
7980
:caption: Development

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sphinx-design
55
ipykernel
66
jupyter-sphinx
77
sphinx-togglebutton
8+
sphinxcontrib-mermaid
89
nbsphinx
910
myst-parser
1011
numpy

0 commit comments

Comments
 (0)