Created
June 21, 2021 01:52
-
-
Save sunhwan/197446cdb29ff2cf0b7562fabf5d31b0 to your computer and use it in GitHub Desktop.
ipython cell magic - kroki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.core.magic import register_cell_magic | |
from IPython.display import SVG, display | |
import requests | |
diagrams_supported = set(['blockdiag', 'seqdiag', 'mermaid', 'actdiag', | |
'nwdiag', 'packetdiag', 'rackdiag', 'erd', | |
'nomnoml', 'plantuml', 'umlet', 'wavedrom', | |
'bpmn', 'bytefield', 'pikchr', 'graphviz', | |
'vega', 'vega-lite', 'ditaa', 'svgbob']) | |
# see https://kroki.io/examples.html#wbs for working examples | |
@register_cell_magic | |
def kroki(line, cell): | |
"simple wrapper for kroki.io" | |
if line not in diagrams_supported: | |
raise NotImplemented | |
url = 'https://kroki.io' | |
r = requests.post(f'{url}/{line}/svg', json={'diagram_source': cell}) | |
if r.status_code == 200: | |
return display(SVG(r.text)) | |
else: | |
raise ValueError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment