diff options
author | Georg Brandl <georg@python.org> | 2011-01-08 15:16:38 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2011-01-08 15:16:38 +0100 |
commit | 8b51e75bd96d1e7aef45a00c2b2572a1f60a372e (patch) | |
tree | a47673f069028a0e3b42dd697db46bfcda4e1fcb /sphinx/ext/graphviz.py | |
parent | c6028c440542f6662fd53232629a5d5b1b398691 (diff) | |
parent | f0f9f7b1b2d54246b7ec77547f3cade6afa20967 (diff) | |
download | sphinx-git-8b51e75bd96d1e7aef45a00c2b2572a1f60a372e.tar.gz |
merge with https://bitbucket.org/dhellmann/sphinx-graphviz-paragraphs/
Diffstat (limited to 'sphinx/ext/graphviz.py')
-rw-r--r-- | sphinx/ext/graphviz.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 0b8e050b2..8f7744b21 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -52,6 +52,7 @@ class Graphviz(Directive): option_spec = { 'alt': directives.unchanged, 'inline': directives.flag, + 'caption': directives.unchanged, } def run(self): @@ -85,6 +86,8 @@ class Graphviz(Directive): node['options'] = [] if 'alt' in self.options: node['alt'] = self.options['alt'] + if 'caption' in self.options: + node['caption'] = self.options['caption'] node['inline'] = 'inline' in self.options return [node] @@ -100,6 +103,7 @@ class GraphvizSimple(Directive): option_spec = { 'alt': directives.unchanged, 'inline': directives.flag, + 'caption': directives.unchanged, } def run(self): @@ -109,6 +113,8 @@ class GraphvizSimple(Directive): node['options'] = [] if 'alt' in self.options: node['alt'] = self.options['alt'] + if 'caption' in self.options: + node['caption'] = self.options['caption'] node['inline'] = 'inline' in self.options return [node] @@ -264,14 +270,25 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'): self.builder.warn('dot code %r: ' % code + str(exc)) raise nodes.SkipNode - if node.get('inline', False): + inline = node.get('inline', False) + if inline: para_separator = '' else: para_separator = '\n' if fname is not None: - self.body.append('%s\\includegraphics{%s}%s' % (para_separator, fname, - para_separator)) + caption = node.get('caption') + if caption: + self.body.append('\n\\begin{figure}[h!]') + self.body.append('\n\\begin{center}') + self.body.append('\n\\caption{%s}' % caption) + self.body.append('\n\\label{figure:%s}' % caption) + self.body.append('\n\\includegraphics{%s}' % fname) + self.body.append('\n\\end{center}') + self.body.append('\n\\end{figure}\n') + else: + self.body.append('%s\\includegraphics{%s}' % + (para_separator, fname, para_separator)) raise nodes.SkipNode |