1"""display mermaid.js diagrams in jupyter notebooks by the `mermaid.ink/img` service"""

2

3 import base64

4

5 try:

6 from IPython.display import Image, display

7 except ImportError:

8 import warnings

9

10 warnings.warn(

11 "IPython.display could not be imported, mermaid will not work", ImportWarning

12 )

13

14

15 def mm(graph):

16 """for plotting mermaid.js diagrams"""

17 graphbytes = graph.encode("ascii")

18 base64_bytes = base64.b64encode(graphbytes)

19 base64_string = base64_bytes.decode("ascii")

20 display(Image(url="https://mermaid.ink/img/" + base64_string))