Skip to content

Commit

Permalink
Fixed two more bugs with SVG inheritance-diagram links
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshih committed Aug 22, 2023
1 parent 6183b6a commit 23b1c30
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Expand Up @@ -11,6 +11,9 @@ Bugs fixed

* Fix regression in ``autodoc.Documenter.parse_name()``.
* Fix regression in JSON serialisation.
* #11634: Fixed two more bugs in inheritance diagrams that resulted in
broken links.
Patch by Albert Shih.

Release 7.2.2 (released Aug 17, 2023)
=====================================
Expand Down
5 changes: 3 additions & 2 deletions sphinx/ext/graphviz.py
Expand Up @@ -235,10 +235,11 @@ def fix_svg_relative_paths(self: SphinxTranslator, filepath: str) -> None:
# not a relative link
continue

old_path = path.join(self.builder.outdir, url)
docdir = path.dirname(path.join(self.builder.outdir, self.builder.current_docname))
old_path = path.join(docdir, url)
new_path = path.relpath(
old_path,
start=path.join(self.builder.outdir, self.builder.imgpath),
start=path.join(docdir, self.builder.imgpath),
)
modified_url = urlunsplit((scheme, hostname, new_path, query, fragment))

Expand Down
3 changes: 2 additions & 1 deletion sphinx/ext/inheritance_diagram.py
Expand Up @@ -36,6 +36,7 @@ class E(B): pass
import re
from collections.abc import Iterable, Sequence
from importlib import import_module
from os import path
from typing import TYPE_CHECKING, Any, cast

from docutils import nodes
Expand Down Expand Up @@ -417,7 +418,7 @@ def html_visit_inheritance_diagram(self: HTML5Translator, node: inheritance_diag

# Create a mapping from fully-qualified class names to URLs.
graphviz_output_format = self.builder.env.config.graphviz_output_format.upper()
current_filename = self.builder.current_docname + self.builder.out_suffix
current_filename = path.basename(self.builder.current_docname + self.builder.out_suffix)
urls = {}
pending_xrefs = cast(Iterable[addnodes.pending_xref], node)
for child in pending_xrefs:
Expand Down
2 changes: 2 additions & 0 deletions tests/roots/test-ext-inheritance_diagram/subdir/index.rst
Expand Up @@ -4,4 +4,6 @@ test-ext-inheritance_diagram subdirectory

.. inheritance-diagram:: test.DocMainLevel

.. inheritance-diagram:: test.DocLowerLevel

.. py:class:: test.DocLowerLevel

0 comments on commit 23b1c30

Please sign in to comment.