Commits

Doug Hellmann committed 9c4c1d6

add 'inline' flag to graphviz extension directives to control paragraph breaks

Comments (0)

Files changed (2)

doc/ext/graphviz.rst

    alternate text for HTML output.  If not given, the alternate text defaults to
    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).
 
 There are also these new config values:
 

sphinx/ext/graphviz.py

     final_argument_whitespace = False
     option_spec = {
         'alt': directives.unchanged,
+        'inline': directives.flag,
     }
 
     def run(self):
         node['options'] = []
         if 'alt' in self.options:
             node['alt'] = self.options['alt']
+        node['inline'] = 'inline' in self.options
         return [node]
 
 
     final_argument_whitespace = False
     option_spec = {
         'alt': directives.unchanged,
+        'inline': directives.flag,
     }
 
     def run(self):
         node['options'] = []
         if 'alt' in self.options:
             node['alt'] = self.options['alt']
+        node['inline'] = 'inline' in self.options
         return [node]
 
 
         self.builder.warn('dot code %r: ' % code + str(exc))
         raise nodes.SkipNode
 
-    self.body.append(self.starttag(node, 'p', CLASS='graphviz'))
+    if node.get('inline', False):
+        wrapper = 'span'
+    else:
+        wrapper = 'p'
+
+    self.body.append(self.starttag(node, wrapper, CLASS='graphviz'))
     if fname is None:
         self.body.append(self.encode(code))
     else:
                                  (fname, alt, mapname, imgcss))
                 self.body.extend(imgmap)
 
-    self.body.append('</p>\n')
+    self.body.append('</%s>\n' % wrapper)
     raise nodes.SkipNode
 
 
         self.builder.warn('dot code %r: ' % code + str(exc))
         raise nodes.SkipNode
 
+    if node.get('inline', False):
+        para_separator = ''
+    else:
+        para_separator = '\n'
+
     if fname is not None:
-        self.body.append('\\includegraphics{%s}' % fname)
+        self.body.append('%s\\includegraphics{%s}%s' % (para_separator, fname, para_separator))
     raise nodes.SkipNode
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.