Skip to content

Instantly share code, notes, and snippets.

@fairchild
Created October 1, 2017 15:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fairchild/fcaac3bb37844d1428448a17bab9f4d3 to your computer and use it in GitHub Desktop.
import urllib
import plantumlencoder
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):
self.filename = line
self.code = ""
for line in cell.split('\n'):
newline = line.strip()
if newline:
self.code += newline + '\n'
uri = "http://www.plantuml.com/plantuml/svg/" + plantumlencoder.compress(self.code)
urllib.urlretrieve(uri, self.filename)
return SVG(filename=self.filename)
def load_ipython_extension(ipython):
ipython.register_magics(Plantuml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment