summaryrefslogtreecommitdiff
path: root/content/resources/rst_graphviz/rst2html.py
diff options
context:
space:
mode:
Diffstat (limited to 'content/resources/rst_graphviz/rst2html.py')
-rwxr-xr-xcontent/resources/rst_graphviz/rst2html.py30
1 files changed, 24 insertions, 6 deletions
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)