Commits

Georg Brandl committed 345d65d

Fix interpolation error, encode inserted caption strings and add the caption in HTML output too.

  • Participants
  • Parent commits b5440a7

Comments (0)

Files changed (4)

 * 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
 
 * #306: Added :event:`env-get-outdated` event.
 
+* #590: Added ``caption`` option to graphviz directives.
+
 * C++ domain now supports array definitions.
 
 

File doc/ext/graphviz.rst

    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:
 

File sphinx/ext/graphviz.py

         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'
                 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
 
     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