mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #2221 from tk0miya/graphviz_inline_by_default
Fix #1149: ``sphinx.ext.graphviz``: show graph image in inline by default
This commit is contained in:
commit
81fd24a565
2
CHANGES
2
CHANGES
@ -14,7 +14,7 @@ Incompatible changes
|
||||
conf.py that will be provided on sphinx-quickstart.
|
||||
* #2027, #2208: The ``html_title`` accepts string values only. And The None value cannot be
|
||||
accepted.
|
||||
|
||||
* ``sphinx.ext.graphviz``: show graph image in inline by default
|
||||
|
||||
Features added
|
||||
--------------
|
||||
|
@ -36,7 +36,7 @@ class GraphvizError(SphinxError):
|
||||
category = 'Graphviz error'
|
||||
|
||||
|
||||
class graphviz(nodes.General, nodes.Element):
|
||||
class graphviz(nodes.General, nodes.Inline, nodes.Element):
|
||||
pass
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ class Graphviz(Directive):
|
||||
node['inline'] = 'inline' in self.options
|
||||
|
||||
caption = self.options.get('caption')
|
||||
if caption and not node['inline']:
|
||||
if caption:
|
||||
node = figure_wrapper(self, node, caption)
|
||||
|
||||
return [node]
|
||||
@ -132,7 +132,7 @@ class GraphvizSimple(Directive):
|
||||
node['inline'] = 'inline' in self.options
|
||||
|
||||
caption = self.options.get('caption')
|
||||
if caption and not node['inline']:
|
||||
if caption:
|
||||
node = figure_wrapper(self, node, caption)
|
||||
|
||||
return [node]
|
||||
@ -197,6 +197,15 @@ def render_dot(self, code, options, format, prefix='graphviz'):
|
||||
return relfn, outfn
|
||||
|
||||
|
||||
def warn_for_deprecated_option(self, node):
|
||||
if hasattr(self.builder, '_graphviz_warned_inline'):
|
||||
return
|
||||
|
||||
if 'inline' in node:
|
||||
self.builder.warn(':inline: option for graphviz is deprecated since version 1.4.0.')
|
||||
self.builder._graphviz_warned_inline = True
|
||||
|
||||
|
||||
def render_dot_html(self, node, code, options, prefix='graphviz',
|
||||
imgcls=None, alt=None):
|
||||
format = self.builder.config.graphviz_output_format
|
||||
@ -209,13 +218,6 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
|
||||
self.builder.warn('dot code %r: ' % code + str(exc))
|
||||
raise nodes.SkipNode
|
||||
|
||||
inline = node.get('inline', False)
|
||||
if inline:
|
||||
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:
|
||||
@ -243,11 +245,11 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
|
||||
(fname, alt, mapname, imgcss))
|
||||
self.body.extend([item.decode('utf-8') for item in imgmap])
|
||||
|
||||
self.body.append('</%s>\n' % wrapper)
|
||||
raise nodes.SkipNode
|
||||
|
||||
|
||||
def html_visit_graphviz(self, node):
|
||||
warn_for_deprecated_option(self, node)
|
||||
render_dot_html(self, node, node['code'], node['options'])
|
||||
|
||||
|
||||
@ -258,8 +260,8 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'):
|
||||
self.builder.warn('dot code %r: ' % code + str(exc))
|
||||
raise nodes.SkipNode
|
||||
|
||||
inline = node.get('inline', False)
|
||||
if inline:
|
||||
is_inline = self.is_inline(node)
|
||||
if is_inline:
|
||||
para_separator = ''
|
||||
else:
|
||||
para_separator = '\n'
|
||||
@ -271,6 +273,7 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'):
|
||||
|
||||
|
||||
def latex_visit_graphviz(self, node):
|
||||
warn_for_deprecated_option(self, node)
|
||||
render_dot_latex(self, node, node['code'], node['options'])
|
||||
|
||||
|
||||
@ -286,10 +289,12 @@ def render_dot_texinfo(self, node, code, options, prefix='graphviz'):
|
||||
|
||||
|
||||
def texinfo_visit_graphviz(self, node):
|
||||
warn_for_deprecated_option(self, node)
|
||||
render_dot_texinfo(self, node, node['code'], node['options'])
|
||||
|
||||
|
||||
def text_visit_graphviz(self, node):
|
||||
warn_for_deprecated_option(self, node)
|
||||
if 'alt' in node.attributes:
|
||||
self.add_text(_('[graph: %s]') % node['alt'])
|
||||
else:
|
||||
@ -298,6 +303,7 @@ def text_visit_graphviz(self, node):
|
||||
|
||||
|
||||
def man_visit_graphviz(self, node):
|
||||
warn_for_deprecated_option(self, node)
|
||||
if 'alt' in node.attributes:
|
||||
self.body.append(_('[graph: %s]') % node['alt'])
|
||||
else:
|
||||
|
@ -2,4 +2,12 @@
|
||||
|
||||
extensions = ['sphinx.ext.graphviz']
|
||||
master_doc = 'index'
|
||||
<<<<<<< 492f60c37185dccee1e42c01fb5d87ed42f45608
|
||||
exclude_patterns = ['_build']
|
||||
=======
|
||||
|
||||
latex_documents = [
|
||||
(master_doc, 'SphinxTests.tex', 'Sphinx Tests Documentation',
|
||||
'Georg Brandl', 'manual'),
|
||||
]
|
||||
>>>>>>> ``sphinx.ext.graphviz``: show graph image in inline by default
|
||||
|
@ -5,3 +5,9 @@ graphviz
|
||||
:caption: caption of graph
|
||||
|
||||
bar -> baz
|
||||
|
||||
.. |graph| digraph:: bar
|
||||
|
||||
bar -> baz
|
||||
|
||||
Hello |graph| graphviz world
|
||||
|
@ -15,12 +15,31 @@ from util import with_app, SkipTest
|
||||
|
||||
|
||||
@with_app('html', testroot='ext-graphviz')
|
||||
def test_graphviz(app, status, warning):
|
||||
def test_graphviz_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
if "dot command 'dot' cannot be run" in warning.getvalue():
|
||||
raise SkipTest('graphviz "dot" is not available')
|
||||
|
||||
content = (app.outdir / 'index.html').text()
|
||||
html = ('<p class="graphviz">\s*<img .*?/>\s*</p>\s*'
|
||||
'<p class="caption"><span class="caption-text">caption of graph</span>')
|
||||
html = ('<div class="figure" .*?>\s*<img .*?/>\s*<p class="caption">'
|
||||
'<span class="caption-text">caption of graph</span>.*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = 'Hello <img .*?/>\n graphviz world'
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@with_app('latex', testroot='ext-graphviz')
|
||||
def test_graphviz_latex(app, status, warning):
|
||||
app.builder.build_all()
|
||||
if "dot command 'dot' cannot be run" in warning.getvalue():
|
||||
raise SkipTest('graphviz "dot" is not available')
|
||||
|
||||
content = (app.outdir / 'SphinxTests.tex').text()
|
||||
macro = ('\\\\begin{figure}\[htbp\]\n\\\\centering\n\\\\capstart\n\n'
|
||||
'\\\\includegraphics{graphviz-\w+.pdf}\n'
|
||||
'\\\\caption{caption of graph}\\\\end{figure}')
|
||||
assert re.search(macro, content, re.S)
|
||||
|
||||
macro = 'Hello \\\\includegraphics{graphviz-\w+.pdf} graphviz world'
|
||||
assert re.search(macro, content, re.S)
|
||||
|
Loading…
Reference in New Issue
Block a user