Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"myst_parser",
"ablog",
"jupyter_sphinx",
"sphinxcontrib.mermaid",
"sphinxcontrib.youtube",
"nbsphinx",
"numpydoc",
Expand Down
1 change: 1 addition & 0 deletions docs/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ See the sections in the primary sidebar and below to explore.
pydata
execution
graphviz
mermaid


.. Note: the caption below is intentionally long in order to test out what long captions look like.
Expand Down
48 changes: 48 additions & 0 deletions docs/examples/mermaid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
========
Mermaid
========
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the over/underlines length need to exactly match the length of the title?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no.


If you use `sphinxcontrib-mermaid <https://github.com/mgaitan/sphinxcontrib-mermaid>`_
to generate flowcharts or diagrams, and you output the diagrams in "raw" format,
they will automatically adapt to this theme's light or dark mode.

To use this feature, you'll need to install `sphinxcontrib-mermaid`_ and add it to your
list of extensions in ``conf.py``:

.. code-block:: python

# conf.py
extensions = [
...,
"sphinxcontrib.mermaid",
]

This will enable the ``.. mermaid::`` directive. For example:

.. begin-example-mermaid
.. mermaid::

gitGraph:
commit
branch newbranch
checkout newbranch
commit id:"1111"
commit tag:"test"
checkout main
commit type: HIGHLIGHT
commit
merge newbranch
commit
branch b2
commit
.. end-example-mermaid

is generated by the following code:

.. include:: ./mermaid.rst
:start-after: begin-example-mermaid
:end-before: .. end-example-mermaid
Comment on lines +43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these values both have a leading .. or none?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first one doesn't need it, but it wouldn't hurt. Second one does need it. I tend to omit .. on the first one so that the text aligns nicely on the two lines.

:code: rst
:class: highlight

See the `Mermaid documentation <https://mermaid.js.org/syntax/examples>`__ for additional examples.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ doc = [
"sphinx-design",
"sphinx-togglebutton",
"jupyterlite-sphinx",
"sphinxcontrib-mermaid",
"sphinxcontrib-youtube>=1.4.1",
"sphinx-favicon>=1.0.1",
"ipykernel",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* sphinxcontrib-mermaid
* ref: https://github.com/mgaitan/sphinxcontrib-mermaid
*/

/* Style the diagram such that it has a dark mode */
html[data-theme="dark"] pre.mermaid > svg {
filter: brightness(0.8) invert(0.82) contrast(1.2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
@import "./extensions/execution";
@import "./extensions/gallery_grid";
@import "./extensions/graphviz";
@import "./extensions/mermaid";
@import "./extensions/pydata";
@import "./extensions/sphinx_design";
@import "./extensions/togglebutton";
Expand Down
Loading