summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-01-08 15:39:35 +0100
committerGeorg Brandl <georg@python.org>2011-01-08 15:39:35 +0100
commit41ae36fe22686928eb8b65278e7392354779e6fb (patch)
tree13d0ee0b6f9fad0fd033bc9b6d399f7add7b7c84
parent4728d8379beb1fb91c096f0973864fc246a0dc29 (diff)
downloadsphinx-41ae36fe22686928eb8b65278e7392354779e6fb.tar.gz
Fix interpolation error, encode inserted caption strings and add the caption in HTML output too.
-rw-r--r--AUTHORS1
-rw-r--r--CHANGES2
-rw-r--r--doc/ext/graphviz.rst13
-rw-r--r--sphinx/ext/graphviz.py14
4 files changed, 21 insertions, 9 deletions
diff --git a/AUTHORS b/AUTHORS
index 09574fbe..44bbbcd4 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 26c63f8b..1cadd742 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 3a6d7c30..9b34b48f 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 8f7744b2..45f3169c 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('<img src="%s" alt="%s" usemap="#%s" %s/>\n' %
(fname, alt, mapname, imgcss))
self.body.extend(imgmap)
+ if node.get('caption') and not inline:
+ self.body.append('</p>\n<p class="caption">')
+ 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