diff --git a/AUTHORS b/AUTHORS
index 09574fbee..44bbbcd42 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -15,6 +15,7 @@ Other contributors, listed alphabetically, are:
* Josip Dzolonga -- coverage builder
* Horst Gutmann -- internationalization support
* Martin Hans -- autodoc improvements
+* Doug Hellmann -- graphviz improvements
* Dave Kuhlman -- original LaTeX writer
* Blaise Laflamme -- pyramid theme
* Thomas Lamb -- linkcheck builder
diff --git a/CHANGES b/CHANGES
index 26c63f8b9..1cadd7420 100644
--- a/CHANGES
+++ b/CHANGES
@@ -77,6 +77,8 @@ Release 1.1 (in development)
* #306: Added :event:`env-get-outdated` event.
+* #590: Added ``caption`` option to graphviz directives.
+
* C++ domain now supports array definitions.
diff --git a/doc/ext/graphviz.rst b/doc/ext/graphviz.rst
index 3a6d7c30e..9b34b48fe 100644
--- a/doc/ext/graphviz.rst
+++ b/doc/ext/graphviz.rst
@@ -73,10 +73,15 @@ It adds these directives:
the graphviz code.
.. versionadded:: 1.1
- All three directives support an ``inline`` flag that controls
- paragraph breaks in the output. When set, the graph is inserted
- into the current paragraph. If the flag is not given, paragraph
- breaks are introduced before and after the image (the default).
+ All three directives support an ``inline`` flag that controls paragraph
+ breaks in the output. When set, the graph is inserted into the current
+ paragraph. If the flag is not given, paragraph breaks are introduced before
+ and after the image (the default).
+
+.. versionadded:: 1.1
+ All three directives support a ``caption`` option that can be used to give a
+ caption to the diagram. Naturally, diagrams marked as "inline" cannot have a
+ caption.
There are also these new config values:
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
index 8f7744b21..45f3169c4 100644
--- a/sphinx/ext/graphviz.py
+++ b/sphinx/ext/graphviz.py
@@ -223,7 +223,8 @@ def render_dot_html(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:
wrapper = 'span'
else:
wrapper = 'p'
@@ -254,6 +255,9 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
self.body.append('\n' %
(fname, alt, mapname, imgcss))
self.body.extend(imgmap)
+ if node.get('caption') and not inline:
+ self.body.append('
') + self.body.append(self.encode(node['caption'])) self.body.append('%s>\n' % wrapper) raise nodes.SkipNode @@ -278,16 +282,16 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'): if fname is not None: caption = node.get('caption') - if caption: + if caption and not inline: 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\\caption{%s}' % self.encode(caption)) + self.body.append('\n\\label{figure:%s}' % self.encode(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}' % + self.body.append('%s\\includegraphics{%s}%s' % (para_separator, fname, para_separator)) raise nodes.SkipNode