mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4866 from goerz/ext_graphviz_css
Wrap graphviz diagrams in <div class="graphviz">
This commit is contained in:
commit
eba8792355
@ -290,21 +290,27 @@ def render_dot_html(self, node, code, options, prefix='graphviz',
|
||||
self.body.append('<div align="%s" class="align-%s">' %
|
||||
(node['align'], node['align']))
|
||||
if format == 'svg':
|
||||
svgtag = '''<object data="%s" type="image/svg+xml">
|
||||
<p class="warning">%s</p></object>\n''' % (fname, alt)
|
||||
self.body.append(svgtag)
|
||||
self.body.append('<div class="graphviz">')
|
||||
self.body.append('<object data="%s" type="image/svg+xml" %s>\n' %
|
||||
(fname, imgcss))
|
||||
self.body.append('<p class="warning">%s</p>' % alt)
|
||||
self.body.append('</object></div>\n')
|
||||
else:
|
||||
with codecs.open(outfn + '.map', 'r', encoding='utf-8') as mapfile: # type: ignore
|
||||
imgmap = ClickableMapDefinition(outfn + '.map', mapfile.read(), dot=code)
|
||||
if imgmap.clickable:
|
||||
# has a map
|
||||
self.body.append('<img src="%s" alt="%s" usemap="#%s" %s/>\n' %
|
||||
self.body.append('<div class="graphviz">')
|
||||
self.body.append('<img src="%s" alt="%s" usemap="#%s" %s/>' %
|
||||
(fname, alt, imgmap.id, imgcss))
|
||||
self.body.append('</div>\n')
|
||||
self.body.append(imgmap.generate_clickable_map())
|
||||
else:
|
||||
# nothing in image map
|
||||
self.body.append('<img src="%s" alt="%s" %s/>\n' %
|
||||
self.body.append('<div class="graphviz">')
|
||||
self.body.append('<img src="%s" alt="%s" %s/>' %
|
||||
(fname, alt, imgcss))
|
||||
self.body.append('</div>\n')
|
||||
if 'align' in node:
|
||||
self.body.append('</div>\n')
|
||||
|
||||
|
@ -22,24 +22,26 @@ def test_graphviz_png_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').text()
|
||||
html = (r'<div class="figure" .*?>\s*<img .*?/>\s*<p class="caption">'
|
||||
html = (r'<div class="figure" .*?>\s*'
|
||||
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
|
||||
r'<span class="caption-text">caption of graph</span>.*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = 'Hello <img .*?/>\n graphviz world'
|
||||
html = 'Hello <div class="graphviz"><img .*?/></div>\n graphviz world'
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = '<img src=".*?" alt="digraph {\n bar -> baz\n}" />'
|
||||
assert re.search(html, content, re.M)
|
||||
|
||||
html = (r'<div class="figure align-right" .*?>\s*<img .*?/>\s*<p class="caption">'
|
||||
html = (r'<div class="figure align-right" .*?>\s*'
|
||||
r'<div class="graphviz"><img .*?/></div>\s*<p class="caption">'
|
||||
r'<span class="caption-text">on right</span>.*</p>\s*</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
html = (r'<div align=\"center\" class=\"align-center\">'
|
||||
r'<img src=\".*\.png\" alt=\"digraph foo {\n'
|
||||
r'<div class="graphviz"><img src=\".*\.png\" alt=\"digraph foo {\n'
|
||||
r'centered\n'
|
||||
r'}\" />\n</div>')
|
||||
r'}\" /></div>\n</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
||||
@ -52,34 +54,34 @@ def test_graphviz_svg_html(app, status, warning):
|
||||
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'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
||||
r'\s*<p class=\"warning\">digraph foo {\n'
|
||||
r'bar -> baz\n'
|
||||
r'}</p></object>\n'
|
||||
r'}</p></object></div>\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'
|
||||
html = (r'Hello <div class="graphviz"><object.*>\n'
|
||||
r'\s*<p class=\"warning\">graph</p></object></div>\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'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
||||
r'\s*<p class=\"warning\">digraph bar {\n'
|
||||
r'foo -> bar\n'
|
||||
r'}</p></object>\n'
|
||||
r'}</p></object></div>\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'<div class="graphviz"><object data=\".*\.svg\".*>\n'
|
||||
r'\s*<p class=\"warning\">digraph foo {\n'
|
||||
r'centered\n'
|
||||
r'}</p></object>\n'
|
||||
r'}</p></object></div>\n'
|
||||
r'</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
|
@ -19,14 +19,34 @@ from sphinx.ext.inheritance_diagram import InheritanceException, import_classes
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-inheritance_diagram')
|
||||
@pytest.mark.usefixtures('if_graphviz_found')
|
||||
def test_inheritance_diagram_html(app, status, warning):
|
||||
def test_inheritance_diagram_png_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').text()
|
||||
|
||||
pattern = ('<div class="figure" id="id1">\n'
|
||||
'<div class="graphviz">'
|
||||
'<img src="_images/inheritance-\\w+.png" alt="Inheritance diagram of test.Foo" '
|
||||
'class="inheritance"/>\n<p class="caption"><span class="caption-text">'
|
||||
'class="inheritance"/></div>\n<p class="caption"><span class="caption-text">'
|
||||
'Test Foo!</span><a class="headerlink" href="#id1" '
|
||||
'title="Permalink to this image">\xb6</a></p>')
|
||||
assert re.search(pattern, content, re.M)
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-inheritance_diagram',
|
||||
confoverrides={'graphviz_output_format': 'svg'})
|
||||
@pytest.mark.usefixtures('if_graphviz_found')
|
||||
def test_inheritance_diagram_svg_html(app, status, warning):
|
||||
app.builder.build_all()
|
||||
|
||||
content = (app.outdir / 'index.html').text()
|
||||
|
||||
pattern = ('<div class="figure" id="id1">\n'
|
||||
'<div class="graphviz">'
|
||||
'<object data="_images/inheritance-\\w+.svg" '
|
||||
'type="image/svg\\+xml" class="inheritance">\n'
|
||||
'<p class=\"warning\">Inheritance diagram of test.Foo</p>'
|
||||
'</object></div>\n<p class="caption"><span class="caption-text">'
|
||||
'Test Foo!</span><a class="headerlink" href="#id1" '
|
||||
'title="Permalink to this image">\xb6</a></p>')
|
||||
assert re.search(pattern, content, re.M)
|
||||
@ -62,8 +82,9 @@ def test_inheritance_diagram_latex_alias(app, status, warning):
|
||||
content = (app.outdir / 'index.html').text()
|
||||
|
||||
pattern = ('<div class="figure" id="id1">\n'
|
||||
'<div class="graphviz">'
|
||||
'<img src="_images/inheritance-\\w+.png" alt="Inheritance diagram of test.Foo" '
|
||||
'class="inheritance"/>\n<p class="caption"><span class="caption-text">'
|
||||
'class="inheritance"/></div>\n<p class="caption"><span class="caption-text">'
|
||||
'Test Foo!</span><a class="headerlink" href="#id1" '
|
||||
'title="Permalink to this image">\xb6</a></p>')
|
||||
assert re.search(pattern, content, re.M)
|
||||
|
Loading…
Reference in New Issue
Block a user