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

This commit is contained in:
Georg Brandl 2008-12-15 11:11:47 +01:00
parent c49d8217e9
commit 44b0929669
2 changed files with 24 additions and 4 deletions

View File

@ -1,6 +1,9 @@
Release 0.5.1 (in development) 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 * #65: Fix storage of depth information for PNGs generated by the
pngmath extension. pngmath extension.

View File

@ -118,6 +118,20 @@ doc_fields_without_arg = {
del _ 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): def handle_doc_fields(node, env):
# don't traverse, only handle field lists that are immediate children # don't traverse, only handle field lists that are immediate children
for child in node.children: for child in node.children:
@ -132,8 +146,7 @@ def handle_doc_fields(node, env):
try: try:
typ, obj = fname.astext().split(None, 1) typ, obj = fname.astext().split(None, 1)
typdesc = _(doc_fields_with_arg[typ]) typdesc = _(doc_fields_with_arg[typ])
if len(fbody.children) == 1 and \ if _is_only_paragraph(fbody):
isinstance(fbody.children[0], nodes.paragraph):
children = fbody.children[0].children children = fbody.children[0].children
else: else:
children = fbody.children children = fbody.children
@ -154,7 +167,11 @@ def handle_doc_fields(node, env):
dlitem += dlpar dlitem += dlpar
params += dlitem params += dlitem
elif typdesc == '%type': 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: else:
fieldname = typdesc + ' ' fieldname = typdesc + ' '
nfield = nodes.field() nfield = nodes.field()
@ -183,7 +200,7 @@ def handle_doc_fields(node, env):
new_list += field new_list += field
for param, type in param_types.iteritems(): for param, type in param_types.iteritems():
if param in param_nodes: 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) child.replace_self(new_list)