It is possible to have sphinx MyST rendering mermaid

1.9k views Asked by At

It is possible to make work mermaid inside \.md file with MyST md driver ?

For now the only way I found is

$ tail conf.py
extensions = [ 'recommonmark', 'sphinxcontrib.mermaid']
from recommonmark.transform import AutoStructify
def setup(app):
    app.add_transform(AutoStructify)
$

The below is rendered with recommonmark:

```mermaid::

  graph LR
    a --> b
```

but not with MyST-parser

I have open this issue in MyST: https://github.com/executablebooks/MyST-Parser/issues/366

Note: recommonmark does not render correctly tables that's why I try to use MyST-parser

3

There are 3 answers

2
AlexTorx On BEST ANSWER

mermaid is prefectly integrated to MyST-parser.

You only need to call it like that with {mermaid}:

```{mermaid}
graph LR
  a --> b
```

No need to define in conf.py a def setup(app): only:

extensions = ['myst_parser', 'sphinxcontrib.mermaid']
0
s-weigand On

As of myst-parser 0.19.2 you can use the regular markdown syntax with mermaid instead of {mermaid}.

This way previews (e.g. on GitHub or in your editor) will also work properly.

The minimal conf.py change that is needed looks like this:

extensions = ['myst_parser', 'sphinxcontrib.mermaid']
myst_fence_as_directive = ["mermaid"]
0
SWHL On

Tips: Need to pip install sphinxcontrib-mermaid

from myst-parser