Skip to content

Instantly share code, notes, and snippets.

@yarko
Forked from sberke/plantuml_magics.py
Last active November 2, 2015 00:09
Show Gist options
  • Save yarko/d2b470b52678e7f5deef to your computer and use it in GitHub Desktop.
Save yarko/d2b470b52678e7f5deef to your computer and use it in GitHub Desktop.
An Plantuml extension for generating UML figures from within ipython notebook.
"""
An Plantuml extension for generating UML figures from within ipython notebook.
Source: http://stackoverflow.com/questions/20303335/ipython-notebook-plantuml-extension
See example notebook at: http://nbviewer.ipython.org/gist/sberke/bb90ff09193a8888d7f7
"""
import os
from IPython.core.magic import magics_class, cell_magic, Magics
from IPython.display import Image, SVG
@magics_class
class Plantuml(Magics):
@cell_magic
def plantuml(self, line, cell):
"""Generate and display a figure using Plantuml.
Usage:
%plantuml -tsvg filname
"""
self.filename = line
self.code = cell
with open(self.filename + ".plt", "w") as file:
file.write(self.code)
os.system("plantuml -tsvg %s.plt" % self.filename)
return SVG(filename=self.filename+".svg")
def load_ipython_extension(ipython):
ipython.register_magics(Plantuml)
@yarko
Copy link
Author

yarko commented Nov 2, 2015

after the extension is installed:

%load_ext plantuml_extension

see http://nbviewer.ipython.org/gist/sberke/bb90ff09193a8888d7f7 for rough example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment