Skip to content

Instantly share code, notes, and snippets.

@sberke
Last active November 1, 2015 21:40
Show Gist options
  • Save sberke/7360a4b7aa79aefccbb0 to your computer and use it in GitHub Desktop.
Save sberke/7360a4b7aa79aefccbb0 to your computer and use it in GitHub Desktop.

Revisions

  1. sberke revised this gist Oct 26, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions plantuml_magics.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@
    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
  2. sberke renamed this gist Oct 26, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. sberke created this gist Oct 26, 2014.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    """
    An Plantuml extension for generating UML figures from within ipython notebook.

    Source: http://stackoverflow.com/questions/20303335/ipython-notebook-plantuml-extension
    """
    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:
    %java -jar plantuml.jar -tsvg filname
    """
    self.filename = line
    self.code = cell

    with open(self.filename + ".plt", "w") as file:
    file.write(self.code)

    os.system("java -jar plantuml.jar -tsvg %s.plt" % self.filename)
    return SVG(filename=self.filename+".svg")

    def load_ipython_extension(ipython):
    ipython.register_magics(Plantuml)