Last active
April 22, 2025 09:34
-
-
Save MLKrisJohnson/2d2df47879ee6afd3be9d6788241fe99 to your computer and use it in GitHub Desktop.
Displaying Mermaid Diagrams in a Jupyter Notebook Using Python
To do it in SVG instead which gives more visually-pleasing results:
import base64
from IPython.display import display_svg
from urllib.request import Request, urlopen
def mm(graph):
graphbytes = graph.encode("ascii")
base64_bytes = base64.b64encode(graphbytes)
base64_string = base64_bytes.decode("ascii")
url="https://mermaid.ink/svg/" + base64_string
req=Request(url, headers={'User-Agent': 'IPython/Notebook'})
display_svg(urlopen(req).read().decode(), raw=True)
More information can be found at https://gist.github.com/diraneyya/1177344d2ead2185c0316f8b5f6ef67b
I have to say that this is the first time I learn that .mmd
is rendered as a Mermaid diagram in GitHub. I know that .md
files do not support Mermaid in Gists which is why this is actually very useful. I am also pleased to see that there are two files in this Gist, which illustrates that Gists are actually just git repositories. Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks