Search code examples
python-sphinxgraphvizcross-reference

Internal reference within a graph using graphviz in Sphinx?


I am trying to create a graph using graphviz in my Sphinx documentation. I managed to include a href in the graph to link an external web page (good example here https://jhermann.github.io/blog/python/documentation/2020/03/25/sphinx_ext_graphviz.html). I would now like do the same but referencing another page of my documentation (using something like :ref:`another page of my documentation` instead of the href). Expected result is: you click on a node of the graph and it opens the corresponding documentation page/ section. Is this possible? Any workarounds for this?


Solution

  • I would assume that any value that you put in an href attribute that works in HTML would also work in graphviz. Try adding a relative path for its value, for example:

    .. graphviz::
        :name: name
    
         digraph "my-digraph" {
             my [label="my-label",
                 shape="component",
                 href="relative/path/to/file.html"
                 target="_blank"];
         }