Skip to content

Commit

Permalink
Fixed two more bugs with 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 4db4089
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
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 @@ -34,6 +34,7 @@ class E(B): pass
import hashlib
import inspect
import re
from os import path
from collections.abc import Iterable, Sequence
from importlib import import_module
from typing import TYPE_CHECKING, Any, cast
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 4db4089

Please sign in to comment.