aboutsummaryrefslogtreecommitdiff
path: root/content/resources
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2013-10-12 19:21:22 +0200
committerSébastien Dailly <sebastien@chimrod.com>2013-10-12 19:21:22 +0200
commit0420a6c83f52e7886d58e4847df4127ab11d17fc (patch)
tree6c3aba71c5db98e4910d8d6dbea5c5923e96b6f5 /content/resources
parentf0833a629dce15f20a1a9a330a0e413beb5a8158 (diff)
Added graphviz 4 rst
Diffstat (limited to 'content/resources')
-rwxr-xr-xcontent/resources/rst_graphviz/rst2html.py61
-rwxr-xr-xcontent/resources/rst_graphviz/rst2latex.py64
2 files changed, 125 insertions, 0 deletions
diff --git a/content/resources/rst_graphviz/rst2html.py b/content/resources/rst_graphviz/rst2html.py
new file mode 100755
index 0000000..ab09012
--- /dev/null
+++ b/content/resources/rst_graphviz/rst2html.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+# $Id: rst2html.py 4564 2006-05-21 20:44:42Z wiemann $
+# Author: David Goodger <goodger@python.org>
+# Copyright: This module has been placed in the public domain.
+
+"""
+A minimal front end to the Docutils Publisher, producing HTML.
+"""
+
+try:
+ import locale
+ locale.setlocale(locale.LC_ALL, '')
+except:
+ pass
+
+import subprocess
+import os.path
+
+from docutils.core import publish_cmdline, default_description
+from docutils.parsers.rst import directives
+from docutils.parsers.rst.directives.images import Figure
+
+
+description = ('Generates (X)HTML documents from standalone reStructuredText '
+ 'sources. ' + default_description)
+
+class Graphviz(Figure):
+ """ Generate a graphviz image
+ """
+ required_arguments = 0
+ optional_arguments = 1
+ final_argument_whitespace = True
+
+ has_content = True
+
+ option_spec = Figure.option_spec.copy()
+
+ def run(self):
+
+ text = '\n'.join(self.content)
+ extension = 'png'
+ imageFile = "tmp/%s.%s" % (hash(text), extension)
+ if not os.path.exists(imageFile):
+ conversion = subprocess.Popen(['/usr/bin/dot',
+ '-T', 'png',
+ '-o', imageFile,
+ ],
+ stdin=subprocess.PIPE
+ )
+ conversion.communicate(text)
+ conversion.wait()
+
+ self.arguments = [imageFile]
+ self.options['scale'] = 50
+ self.content = None
+ return Figure.run(self)
+
+directives.register_directive('graphviz', Graphviz)
+
+publish_cmdline(writer_name='html', description=description)
diff --git a/content/resources/rst_graphviz/rst2latex.py b/content/resources/rst_graphviz/rst2latex.py
new file mode 100755
index 0000000..9185405
--- /dev/null
+++ b/content/resources/rst_graphviz/rst2latex.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+
+# $Id: rst2latex.py 5905 2009-04-16 12:04:49Z milde $
+# Author: David Goodger <goodger@python.org>
+# Copyright: This module has been placed in the public domain.
+
+"""
+A minimal front end to the Docutils Publisher, producing LaTeX.
+"""
+
+try:
+ import locale
+ locale.setlocale(locale.LC_ALL, '')
+except:
+ pass
+
+import subprocess
+import os.path
+
+from docutils.core import publish_cmdline
+from docutils.parsers.rst import directives
+from docutils.parsers.rst.directives.images import Figure
+
+description = ('Generates LaTeX documents from standalone reStructuredText '
+ 'sources. '
+ 'Reads from <source> (default is stdin) and writes to '
+ '<destination> (default is stdout). See '
+ '<http://docutils.sourceforge.net/docs/user/latex.html> for '
+ 'the full reference.')
+
+class Graphviz(Figure):
+ """ Generate a graphviz image
+ """
+ required_arguments = 0
+ optional_arguments = 1
+ final_argument_whitespace = True
+
+ has_content = True
+
+ option_spec = Figure.option_spec.copy()
+
+ def run(self):
+
+ text = '\n'.join(self.content)
+ extension = 'png'
+ imageFile = "tmp/%s.%s" % (hash(text), extension)
+ if not os.path.exists(imageFile):
+ conversion = subprocess.Popen(['/usr/bin/dot',
+ '-T', 'png',
+ '-o', imageFile,
+ ],
+ stdin=subprocess.PIPE
+ )
+ conversion.communicate(text)
+ conversion.wait()
+
+ self.arguments = [imageFile]
+ self.options['scale'] = 50
+ self.content = None
+ return Figure.run(self)
+
+directives.register_directive('graphviz', Graphviz)
+
+publish_cmdline(writer_name='latex', description=description)