summaryrefslogtreecommitdiff
path: root/sphinx/util/docfields.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util/docfields.py')
-rw-r--r--sphinx/util/docfields.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py
index 2f952d7cc..202616337 100644
--- a/sphinx/util/docfields.py
+++ b/sphinx/util/docfields.py
@@ -288,6 +288,12 @@ class DocFieldTransformer(object):
fieldtype, fieldarg = fieldname.astext(), ''
typedesc, is_typefield = typemap.get(fieldtype, (None, None))
+ # collect the content, trying not to keep unnecessary paragraphs
+ if _is_single_paragraph(fieldbody):
+ content = fieldbody.children[0].children
+ else:
+ content = fieldbody.children
+
# sort out unknown fields
if typedesc is None or typedesc.has_arg != bool(fieldarg):
# either the field name is unknown, or the argument doesn't
@@ -297,16 +303,27 @@ class DocFieldTransformer(object):
new_fieldname += ' ' + fieldarg
fieldname[0] = nodes.Text(new_fieldname)
entries.append(field)
+
+ # but if this has a type then we can at least link it
+ if typedesc and is_typefield and content:
+ target = content[0].astext()
+ xrefs = typedesc.make_xrefs(
+ typedesc.typerolename,
+ self.directive.domain,
+ target,
+ contnode=content[0],
+ )
+ if _is_single_paragraph(fieldbody):
+ fieldbody.children[0].clear()
+ fieldbody.children[0].extend(xrefs)
+ else:
+ fieldbody.clear()
+ fieldbody.extend(xrefs)
+
continue
typename = typedesc.name
- # collect the content, trying not to keep unnecessary paragraphs
- if _is_single_paragraph(fieldbody):
- content = fieldbody.children[0].children
- else:
- content = fieldbody.children
-
# if the field specifies a type, put it in the types collection
if is_typefield:
# filter out only inline nodes; others will result in invalid