Skip to content

Commit

Permalink
Addressed comments and added changelog entry
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshih committed Oct 1, 2022
1 parent dd557a5 commit 207cdec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Features added

* #10840: One can cross-reference including an option value: ``:option:`--module=foobar```.
Patch by Martin Liska.
* #10614: Fixed a number of bugs in inheritance diagrams that resulted in
missing or broken links

Bugs fixed
----------
Expand Down
16 changes: 8 additions & 8 deletions sphinx/ext/inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class E(B): pass

import builtins
import inspect
import pathlib
import posixpath
import re
from importlib import import_module
from typing import Any, Dict, Iterable, List, Optional, Tuple, cast
Expand Down Expand Up @@ -402,21 +402,21 @@ def html_visit_inheritance_diagram(self: HTMLTranslator, node: inheritance_diagr
# 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_dir = pathlib.PurePath(current_filename).parent
current_dir = posixpath.dirname(current_filename)
urls = {}
pending_xrefs = cast(Iterable[addnodes.pending_xref], node)
for child in pending_xrefs:
if child.get('refuri') is not None:
# Construct the name from the URI if the reference is external via intersphinx
if not child.get('internal', True):
refname = child['refuri'].rsplit('#', 1)[-1]
else:
if child.get('internal', True):
refname = child['reftitle']
else:
refname = child['refuri'].rsplit('#', 1)[-1]

# For SVG output, relative URIs need to be re-pathed to where the SVG file will be
if graphviz_output_format == 'SVG' and '://' not in child['refuri']:
# URI relative to src dir (typically equivalent to stripping all leading ../)
uri_rel_to_srcdir = (current_dir / child['refuri']).as_posix()
uri_rel_to_srcdir = posixpath.join(current_dir, child['refuri'])
# URI relative to image dir (typically equivalent to prepending ../)
uri_rel_to_imagedir = relpath(uri_rel_to_srcdir, self.builder.imagedir)
urls[refname] = canon_path(uri_rel_to_imagedir)
Expand All @@ -426,8 +426,8 @@ def html_visit_inheritance_diagram(self: HTMLTranslator, node: inheritance_diagr
if graphviz_output_format == 'SVG':
# URI relative to image dir (typically equivalent to prepending ../)
uri_rel_to_imagedir = relpath(current_filename, self.builder.imagedir)
urls[child['reftitle']] = canon_path(uri_rel_to_imagedir) +\
'#' + child.get('refid')
urls[child['reftitle']] = (canon_path(uri_rel_to_imagedir) +
'#' + child.get('refid'))
else:
urls[child['reftitle']] = '#' + child.get('refid')

Expand Down

0 comments on commit 207cdec

Please sign in to comment.