summaryrefslogtreecommitdiff
path: root/sphinx/domains
diff options
context:
space:
mode:
authorJeremy Maitin-Shepard <jbms@google.com>2022-09-06 15:34:20 -0700
committerGitHub <noreply@github.com>2022-09-06 23:34:20 +0100
commit4cd950e1ba1e666c838521871e374ec7ea0bc414 (patch)
tree0ca3cc57dff3b3750506f033a318a3d0354837bd /sphinx/domains
parent5e9550c78e3421dd7dcab037021d996841178f67 (diff)
downloadsphinx-git-4cd950e1ba1e666c838521871e374ec7ea0bc414.tar.gz
Allow `:ref:` role to be used with definitions and fields (#10781)
Diffstat (limited to 'sphinx/domains')
-rw-r--r--sphinx/domains/std.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index d985e5d3a..b0d21b492 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -757,12 +757,21 @@ class StandardDomain(Domain):
if not sectname:
continue
else:
- toctree = next(node.findall(addnodes.toctree), None)
- if toctree and toctree.get('caption'):
- sectname = toctree.get('caption')
+ if (isinstance(node, (nodes.definition_list,
+ nodes.field_list)) and
+ node.children):
+ node = cast(nodes.Element, node.children[0])
+ if isinstance(node, (nodes.field, nodes.definition_list_item)):
+ node = cast(nodes.Element, node.children[0])
+ if isinstance(node, (nodes.term, nodes.field_name)):
+ sectname = clean_astext(node)
else:
- # anonymous-only labels
- continue
+ toctree = next(node.findall(addnodes.toctree), None)
+ if toctree and toctree.get('caption'):
+ sectname = toctree.get('caption')
+ else:
+ # anonymous-only labels
+ continue
self.labels[name] = docname, labelid, sectname
def add_program_option(self, program: str, name: str, docname: str, labelid: str) -> None: