summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-07-11 19:33:47 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-07-11 19:33:47 +0900
commit4a2f5df9ba277f6ce2ad77812a57133a822758e9 (patch)
tree9e6e27972e8aff928c3b81a253843cbb64c41e59
parent573db836beddf26035338a3c44dcace1e08c6d12 (diff)
parente6d3adf5d9748f5253deb8fdf8f43bde160fbac7 (diff)
downloadsphinx-git-4a2f5df9ba277f6ce2ad77812a57133a822758e9.tar.gz
Merge branch '9299' into 4.x
-rw-r--r--sphinx/ext/intersphinx.py23
-rw-r--r--tests/test_ext_intersphinx.py10
2 files changed, 31 insertions, 2 deletions
diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py
index 0797a7c7c..4795d1ae2 100644
--- a/sphinx/ext/intersphinx.py
+++ b/sphinx/ext/intersphinx.py
@@ -305,9 +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:
- 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
- proj, version, uri, dispname = inventory[objtype][target]
+ 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)
diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py
index 875f14346..28b5e63b1 100644
--- a/tests/test_ext_intersphinx.py
+++ b/tests/test_ext_intersphinx.py
@@ -196,6 +196,16 @@ def test_missing_reference_pydomain(tempdir, app, status, warning):
rn = missing_reference(app, app.env, node, contnode)
assert rn.astext() == 'Foo.bar'
+ # term reference (normal)
+ node, contnode = fake_node('std', 'term', 'a term', 'a term')
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn.astext() == 'a term'
+
+ # term reference (case insensitive)
+ node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM')
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn.astext() == 'A TERM'
+
def test_missing_reference_stddomain(tempdir, app, status, warning):
inv_file = tempdir / 'inventory'