From 2fba32dd916c20d5684d3aed8e3c5622c0a1cef4 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 5 May 2014 21:36:19 +0200 Subject: Update post about graphviz --- content/resources/rst_graphviz/rst2html.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'content/resources/rst_graphviz/rst2html.py') diff --git a/content/resources/rst_graphviz/rst2html.py b/content/resources/rst_graphviz/rst2html.py index ab09012..953ee97 100755 --- a/content/resources/rst_graphviz/rst2html.py +++ b/content/resources/rst_graphviz/rst2html.py @@ -8,6 +8,10 @@ A minimal front end to the Docutils Publisher, producing HTML. """ +import sys +reload(sys) +sys.setdefaultencoding('utf-8') + try: import locale locale.setlocale(locale.LC_ALL, '') @@ -28,8 +32,8 @@ description = ('Generates (X)HTML documents from standalone reStructuredText ' class Graphviz(Figure): """ Generate a graphviz image """ - required_arguments = 0 - optional_arguments = 1 + required_arguments = 1 + optional_arguments = 0 final_argument_whitespace = True has_content = True @@ -38,22 +42,36 @@ class Graphviz(Figure): def run(self): - text = '\n'.join(self.content) + if self.content.count("..") == 0: + sep = -1 + text = '\n'.join(self.content) + else: + sep = self.content.index("..") + text = '\n'.join(self.content[:sep]) extension = 'png' imageFile = "tmp/%s.%s" % (hash(text), extension) if not os.path.exists(imageFile): - conversion = subprocess.Popen(['/usr/bin/dot', + conversion = subprocess.Popen(['dot', '-T', 'png', + "-Gcharset=utf8", '-o', imageFile, ], stdin=subprocess.PIPE ) - conversion.communicate(text) + try: + conversion.stdin.write("%s G { \n %s \n}" % (self.arguments[0], + text.encode("utf-8"))) + except: + pass + conversion.stdin.close() conversion.wait() self.arguments = [imageFile] self.options['scale'] = 50 - self.content = None + if sep == -1: + self.content = None + else: + self.content = self.content[sep+1:] return Figure.run(self) directives.register_directive('graphviz', Graphviz) -- cgit v1.2.3