mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Somewhat more efficient fix.
Only looks for case insensitive match if there isn't a case sensitive one, and uses filter to build a list of case insensitive matches rather than building a dict.
This commit is contained in:
parent
732a7d673d
commit
676983e177
@ -305,19 +305,28 @@ def missing_reference(app: Sphinx, env: BuildEnvironment, node: pending_xref,
|
||||
to_try.append((inventories.named_inventory[setname], full_qualified_name))
|
||||
for inventory, target in to_try:
|
||||
for objtype in objtypes:
|
||||
# Special case handling for term to search in a case insensitive fashion
|
||||
if objtype == 'std:term' and objtype in inventory:
|
||||
cased_keys = {k.lower(): k for k in inventory[objtype].keys()}
|
||||
if target.lower() in cased_keys:
|
||||
corrected_target = cased_keys[target.lower()]
|
||||
proj, version, uri, dispname = inventory[objtype][corrected_target]
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
# Default behaviour pre-patch
|
||||
if objtype not in inventory or target not in inventory[objtype]:
|
||||
if objtype not in inventory:
|
||||
# Continue if there's nothing of this kind in the inventory
|
||||
continue
|
||||
if target in inventory[objtype]:
|
||||
# Case sensitive match, use it
|
||||
proj, version, uri, dispname = inventory[objtype][target]
|
||||
elif objtype == 'std:term':
|
||||
# Check for potential case insensitive matches for terms only
|
||||
target_lower = target.lower()
|
||||
insensitive_matches = list(filter(lambda k: k.lower() == target_lower,
|
||||
inventory[objtype].keys()))
|
||||
if insensitive_matches:
|
||||
proj, version, uri, dispname = inventory[objtype][insensitive_matches[0]]
|
||||
else:
|
||||
# No case insensitive match either, continue to the next candidate
|
||||
continue
|
||||
else:
|
||||
# Could reach here if we're not a term but have a case insensitive match.
|
||||
# This is a fix for terms specifically, but potentially should apply to
|
||||
# other types.
|
||||
continue
|
||||
|
||||
if '://' not in uri and node.get('refdoc'):
|
||||
# get correct path in case of subdirectories
|
||||
uri = path.join(relative_path(node['refdoc'], '.'), uri)
|
||||
|
Loading…
Reference in New Issue
Block a user