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

This commit is contained in:
Doug Hellmann 2010-09-16 09:29:04 -04:00
parent 242555d6ca
commit 4a00029a43
2 changed files with 22 additions and 3 deletions

View File

@ -72,6 +72,11 @@ It adds these directives:
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:

View File

@ -51,6 +51,7 @@ class Graphviz(Directive):
final_argument_whitespace = False
option_spec = {
'alt': directives.unchanged,
'inline': directives.flag,
}
def run(self):
@ -84,6 +85,7 @@ class Graphviz(Directive):
node['options'] = []
if 'alt' in self.options:
node['alt'] = self.options['alt']
node['inline'] = 'inline' in self.options
return [node]
@ -97,6 +99,7 @@ class GraphvizSimple(Directive):
final_argument_whitespace = False
option_spec = {
'alt': directives.unchanged,
'inline': directives.flag,
}
def run(self):
@ -106,6 +109,7 @@ class GraphvizSimple(Directive):
node['options'] = []
if 'alt' in self.options:
node['alt'] = self.options['alt']
node['inline'] = 'inline' in self.options
return [node]
@ -213,7 +217,12 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
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:
@ -240,7 +249,7 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
(fname, alt, mapname, imgcss))
self.body.extend(imgmap)
self.body.append('</p>\n')
self.body.append('</%s>\n' % wrapper)
raise nodes.SkipNode
@ -255,8 +264,13 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'):
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