mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4055 from oliver-sanders/fix-graphviz-svg-alignment
Fix ext.graphviz alignment.
This commit is contained in:
commit
8f20132926
@ -246,14 +246,14 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
|
|||||||
if alt is None:
|
if alt is None:
|
||||||
alt = node.get('alt', self.encode(code).strip())
|
alt = node.get('alt', self.encode(code).strip())
|
||||||
imgcss = imgcls and 'class="%s"' % imgcls or ''
|
imgcss = imgcls and 'class="%s"' % imgcls or ''
|
||||||
|
if 'align' in node:
|
||||||
|
self.body.append('<div align="%s" class="align-%s">' %
|
||||||
|
(node['align'], node['align']))
|
||||||
if format == 'svg':
|
if format == 'svg':
|
||||||
svgtag = '''<object data="%s" type="image/svg+xml">
|
svgtag = '''<object data="%s" type="image/svg+xml">
|
||||||
<p class="warning">%s</p></object>\n''' % (fname, alt)
|
<p class="warning">%s</p></object>\n''' % (fname, alt)
|
||||||
self.body.append(svgtag)
|
self.body.append(svgtag)
|
||||||
else:
|
else:
|
||||||
if 'align' in node:
|
|
||||||
self.body.append('<div align="%s" class="align-%s">' %
|
|
||||||
(node['align'], node['align']))
|
|
||||||
with open(outfn + '.map', 'rb') as mapfile:
|
with open(outfn + '.map', 'rb') as mapfile:
|
||||||
imgmap = mapfile.readlines()
|
imgmap = mapfile.readlines()
|
||||||
if len(imgmap) == 2:
|
if len(imgmap) == 2:
|
||||||
@ -266,8 +266,8 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
|
|||||||
self.body.append('<img src="%s" alt="%s" usemap="#%s" %s/>\n' %
|
self.body.append('<img src="%s" alt="%s" usemap="#%s" %s/>\n' %
|
||||||
(fname, alt, mapname, imgcss))
|
(fname, alt, mapname, imgcss))
|
||||||
self.body.extend([item.decode('utf-8') for item in imgmap])
|
self.body.extend([item.decode('utf-8') for item in imgmap])
|
||||||
if 'align' in node:
|
if 'align' in node:
|
||||||
self.body.append('</div>\n')
|
self.body.append('</div>\n')
|
||||||
|
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
@ -286,24 +286,26 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'):
|
|||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
is_inline = self.is_inline(node)
|
is_inline = self.is_inline(node)
|
||||||
if is_inline:
|
|
||||||
para_separator = ''
|
|
||||||
else:
|
|
||||||
para_separator = '\n'
|
|
||||||
|
|
||||||
if fname is not None:
|
if not is_inline:
|
||||||
post = None # type: unicode
|
pre = ''
|
||||||
if not is_inline and 'align' in node:
|
post = ''
|
||||||
|
if 'align' in node:
|
||||||
if node['align'] == 'left':
|
if node['align'] == 'left':
|
||||||
self.body.append('{')
|
pre = '{'
|
||||||
post = '\\hspace*{\\fill}}'
|
post = r'\hspace*{\fill}}'
|
||||||
elif node['align'] == 'right':
|
elif node['align'] == 'right':
|
||||||
self.body.append('{\\hspace*{\\fill}')
|
pre = r'{\hspace*{\fill}'
|
||||||
post = '}'
|
post = '}'
|
||||||
self.body.append('%s\\includegraphics{%s}%s' %
|
elif node['align'] == 'center':
|
||||||
(para_separator, fname, para_separator))
|
pre = r'{\hfill'
|
||||||
if post:
|
post = r'\hspace*{\fill}}'
|
||||||
self.body.append(post)
|
self.body.append('\n%s' % pre)
|
||||||
|
|
||||||
|
self.body.append(r'\includegraphics{%s}' % fname)
|
||||||
|
|
||||||
|
if not is_inline:
|
||||||
|
self.body.append('%s\n' % post)
|
||||||
|
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
|
@ -25,3 +25,8 @@ Hello |graph| graphviz world
|
|||||||
:caption: on right
|
:caption: on right
|
||||||
|
|
||||||
foo -> bar
|
foo -> bar
|
||||||
|
|
||||||
|
.. digraph:: foo
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
centered
|
||||||
|
@ -16,7 +16,7 @@ import pytest
|
|||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='ext-graphviz')
|
@pytest.mark.sphinx('html', testroot='ext-graphviz')
|
||||||
@pytest.mark.usefixtures('if_graphviz_found')
|
@pytest.mark.usefixtures('if_graphviz_found')
|
||||||
def test_graphviz_html(app, status, warning):
|
def test_graphviz_png_html(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
|
||||||
content = (app.outdir / 'index.html').text()
|
content = (app.outdir / 'index.html').text()
|
||||||
@ -34,6 +34,51 @@ def test_graphviz_html(app, status, warning):
|
|||||||
r'<span class="caption-text">on right</span>.*</p>\s*</div>')
|
r'<span class="caption-text">on right</span>.*</p>\s*</div>')
|
||||||
assert re.search(html, content, re.S)
|
assert re.search(html, content, re.S)
|
||||||
|
|
||||||
|
html = (r'<div align=\"center\" class=\"align-center\">'
|
||||||
|
r'<img src=\".*\.png\" alt=\"digraph foo {\n'
|
||||||
|
r'centered\n'
|
||||||
|
r'}\" />\n</div>')
|
||||||
|
assert re.search(html, content, re.S)
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='ext-graphviz',
|
||||||
|
confoverrides={'graphviz_output_format': 'svg'})
|
||||||
|
@pytest.mark.usefixtures('if_graphviz_found')
|
||||||
|
def test_graphviz_svg_html(app, status, warning):
|
||||||
|
app.builder.build_all()
|
||||||
|
|
||||||
|
content = (app.outdir / 'index.html').text()
|
||||||
|
|
||||||
|
html = (r'<div class=\"figure\" .*?>\n'
|
||||||
|
r'<object data=\".*\.svg\".*>\n'
|
||||||
|
r'\s+<p class=\"warning\">digraph foo {\n'
|
||||||
|
r'bar -> baz\n'
|
||||||
|
r'}</p></object>\n'
|
||||||
|
r'<p class=\"caption\"><span class=\"caption-text\">'
|
||||||
|
r'caption of graph</span>.*</p>\n</div>')
|
||||||
|
assert re.search(html, content, re.S)
|
||||||
|
|
||||||
|
html = (r'Hello <object.*>\n'
|
||||||
|
r'\s+<p class=\"warning\">graph</p></object>\n'
|
||||||
|
r' graphviz world')
|
||||||
|
assert re.search(html, content, re.S)
|
||||||
|
|
||||||
|
html = (r'<div class=\"figure align-right\" .*\>\n'
|
||||||
|
r'<object data=\".*\.svg\".*>\n'
|
||||||
|
r'\s+<p class=\"warning\">digraph bar {\n'
|
||||||
|
r'foo -> bar\n'
|
||||||
|
r'}</p></object>\n'
|
||||||
|
r'<p class=\"caption\"><span class=\"caption-text\">'
|
||||||
|
r'on right</span>.*</p>\n'
|
||||||
|
r'</div>')
|
||||||
|
assert re.search(html, content, re.S)
|
||||||
|
|
||||||
|
html = (r'<div align=\"center\" class=\"align-center\">'
|
||||||
|
r'<object data=\".*\.svg\".*>\n'
|
||||||
|
r'\s+<p class=\"warning\">digraph foo {\n'
|
||||||
|
r'centered\n'
|
||||||
|
r'}</p></object>\n'
|
||||||
|
r'</div>')
|
||||||
|
assert re.search(html, content, re.S)
|
||||||
|
|
||||||
@pytest.mark.sphinx('latex', testroot='ext-graphviz')
|
@pytest.mark.sphinx('latex', testroot='ext-graphviz')
|
||||||
@pytest.mark.usefixtures('if_graphviz_found')
|
@pytest.mark.usefixtures('if_graphviz_found')
|
||||||
@ -54,6 +99,11 @@ def test_graphviz_latex(app, status, warning):
|
|||||||
'\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}')
|
'\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}')
|
||||||
assert re.search(macro, content, re.S)
|
assert re.search(macro, content, re.S)
|
||||||
|
|
||||||
|
macro = (r'\{\\hfill'
|
||||||
|
r'\\includegraphics{graphviz-.*}'
|
||||||
|
r'\\hspace\*{\\fill}}')
|
||||||
|
assert re.search(macro, content, re.S)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='ext-graphviz', confoverrides={'language': 'xx'})
|
@pytest.mark.sphinx('html', testroot='ext-graphviz', confoverrides={'language': 'xx'})
|
||||||
@pytest.mark.usefixtures('if_graphviz_found')
|
@pytest.mark.usefixtures('if_graphviz_found')
|
||||||
|
Loading…
Reference in New Issue
Block a user