mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix relative references in SVGs generated by `sphinx.ext.graphviz` (#11078)
Co-authored-by: Ralf Grubenmann <ralf.grubenmann@gmail.com> Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
8
tests/roots/test-ext-graphviz/_static/images/test.svg
Normal file
8
tests/roots/test-ext-graphviz/_static/images/test.svg
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg version="1.1"
|
||||
height="128" width="128"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
|
||||
<rect width="100%" height="100%" fill="red" />
|
||||
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 187 B |
@@ -1,2 +1,3 @@
|
||||
extensions = ['sphinx.ext.graphviz']
|
||||
exclude_patterns = ['_build']
|
||||
html_static_path = ["_static"]
|
||||
|
||||
@@ -31,3 +31,13 @@ Hello |graph| graphviz world
|
||||
:align: center
|
||||
|
||||
centered
|
||||
|
||||
.. graphviz::
|
||||
:align: center
|
||||
|
||||
digraph test {
|
||||
foo [label="foo", URL="#graphviz", target="_parent"]
|
||||
bar [label="bar", image="./_static/images/test.svg"]
|
||||
baz [label="baz", URL="./_static/images/test.svg"]
|
||||
foo -> bar -> baz
|
||||
}
|
||||
|
||||
@@ -82,6 +82,17 @@ def test_graphviz_svg_html(app, status, warning):
|
||||
r'</div>')
|
||||
assert re.search(html, content, re.S)
|
||||
|
||||
image_re = r'.*data="([^"]+)".*?digraph test'
|
||||
image_path_match = re.search(image_re, content, re.S)
|
||||
assert image_path_match
|
||||
|
||||
image_path = image_path_match.group(1)
|
||||
image_content = (app.outdir / image_path).read_text(encoding='utf8')
|
||||
assert '"./_static/' not in image_content
|
||||
assert '<ns0:image ns1:href="../_static/images/test.svg"' in image_content
|
||||
assert '<ns0:a ns1:href="../_static/images/test.svg"' in image_content
|
||||
assert '<ns0:a ns1:href="..#graphviz"' in image_content
|
||||
|
||||
|
||||
@pytest.mark.sphinx('latex', testroot='ext-graphviz')
|
||||
@pytest.mark.usefixtures('if_graphviz_found')
|
||||
|
||||
Reference in New Issue
Block a user