Commits

Doug Hellmann committed 651fa18

add caption option to graphviz nodes and render the caption in latex output

Comments (0)

Files changed (1)

sphinx/ext/graphviz.py

     option_spec = {
         'alt': directives.unchanged,
         'inline': directives.flag,
+        'caption': directives.unchanged,
     }
 
     def run(self):
         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]
 
     option_spec = {
         'alt': directives.unchanged,
         'inline': directives.flag,
+        'caption': directives.unchanged,
     }
 
     def run(self):
         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]
 
         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