Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sphinx/util/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,31 @@ def escape(string: str) -> str:

# body
compressor = zlib.compressobj(9)
# Special pages not generated by singlehtml builder
singlehtml_excluded_pages = {'genindex', 'search', 'modindex', 'py-modindex'}
for domain in env.domains.sorted():
sorted_objects = sorted(domain.get_objects())
for fullname, dispname, type, docname, anchor, prio in sorted_objects:
# Skip pages that singlehtml builder doesn't generate
if builder.name == 'singlehtml' and docname in singlehtml_excluded_pages:
continue

if anchor.endswith(fullname):
# this can shorten the inventory by as much as 25%
anchor = anchor.removesuffix(fullname) + '$'
uri = builder.get_target_uri(docname)

# For singlehtml builder, prepend the output filename to anchor-only URIs
# so intersphinx knows which file to reference
if builder.name == 'singlehtml' and uri.startswith('#'):
if anchor:
# When there's a specific anchor, use just the filename
# (not #document-xxx) to avoid double anchors
uri = builder.config.root_doc + builder.out_suffix
else:
# No specific anchor, keep the #document-xxx part
uri = builder.config.root_doc + builder.out_suffix + uri

if anchor:
uri += '#' + anchor
if dispname == fullname:
Expand Down
Loading