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:
Ralf Grubenmann
2023-07-28 06:47:23 +02:00
committed by GitHub
parent 2c0b81d88b
commit 6178163cb1
6 changed files with 75 additions and 4 deletions

View 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

View File

@@ -1,2 +1,3 @@
extensions = ['sphinx.ext.graphviz']
exclude_patterns = ['_build']
html_static_path = ["_static"]

View File

@@ -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
}

View File

@@ -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')