Skip to content

Relative references in graphviz svgs have the wrong root #11077

@Panaetius

Description

@Panaetius

Describe the bug

When including a graphviz graph that itself has a reference to a file by relative path (embedded image or hyperlink), the link target is wrong in the rendered docs when using svg format.

This is because the rendered graphviz file is put in the _images folder in the built documentation, irrespective of where the original documentation file was, hence any relative path (e.g.../../_stativ/image.svg) is now invalid since the root of the graph changed.

I have a PR that would fix this by rewriting relative URLs in generated SVGs

How to Reproduce

index.rst:

graphviz
========

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

conf.py:

extensions = ['sphinx.ext.graphviz']
exclude_patterns = ['_build']
html_static_path = ["_static"]

The rendered svg still points to e.g. ./_static/images/test.svg, even though since it's now in _images/, it should be ../_static/images/test.svg

Environment Information

Platform:              linux; (Linux-6.1.1-arch1-1-x86_64-with-glibc2.36)
Python version:        3.9.15 (main, Nov 18 2022, 14:40:14)
[GCC 12.2.0])
Python implementation: CPython
Sphinx version:        6.0.0
Docutils version:      0.19
Jinja2 version:        3.0.3

Sphinx extensions

`['sphinx.ext.graphviz']`

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    extensions:graphvizThe `sphinx.ext.graphviz` or `sphinx.ext.inheritance_diagram` extensions

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions