Georg Brandl avatar Georg Brandl committed c62c9b8

Fix handling of :param: and :type: with roles.

Comments (0)

Files changed (2)

 Release 0.5.1 (in development)
 ==============================
 
+* Fix the handling of ``:param:`` and ``:type:`` doc fields when
+  they contain markup (especially cross-referencing roles).
+
 * #65: Fix storage of depth information for PNGs generated by the
   pngmath extension.
 

sphinx/directives/desc.py

 
 del _
 
+
+def _is_only_paragraph(node):
+    # determine if the node only contains one paragraph (and system messages)
+    if len(node) == 0:
+        return False
+    elif len(node) > 1:
+        for subnode in node[1:]:
+            if not isinstance(subnode, nodes.system_message):
+                return False
+    if isinstance(node[0], nodes.paragraph):
+        return True
+    return False
+
+
 def handle_doc_fields(node, env):
     # don't traverse, only handle field lists that are immediate children
     for child in node.children:
             try:
                 typ, obj = fname.astext().split(None, 1)
                 typdesc = _(doc_fields_with_arg[typ])
-                if len(fbody.children) == 1 and \
-                   isinstance(fbody.children[0], nodes.paragraph):
+                if _is_only_paragraph(fbody):
                     children = fbody.children[0].children
                 else:
                     children = fbody.children
                     dlitem += dlpar
                     params += dlitem
                 elif typdesc == '%type':
-                    param_types[obj] = fbody.astext()
+                    typenodes = fbody.children
+                    if _is_only_paragraph(fbody):
+                        typenodes = [nodes.Text(' (')] + \
+                                    typenodes[0].children + [nodes.Text(')')]
+                    param_types[obj] = typenodes
                 else:
                     fieldname = typdesc + ' '
                     nfield = nodes.field()
                 new_list += field
         for param, type in param_types.iteritems():
             if param in param_nodes:
-                param_nodes[param].insert(1, nodes.Text(' (%s)' % type))
+                param_nodes[param][1:1] = type
         child.replace_self(new_list)
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.