in doc/ext/doxygen.py [0:0]
def traverse(self, node, owner):
"""
If an API description is nested in another description,
lookup the child in the context of the parent
"""
# nodes.Text iterates over characters, not children
for child in node.children:
if isinstance(child, addnodes.desc):
for desc_child in child.children:
if isinstance(desc_child, addnodes.desc_signature):
# Get the name of the object. An owner in the signature
# overrides an owner from a parent description.
signature_owner = None
for child in desc_child.children:
if isinstance(child, addnodes.desc_addname):
# An owner in the signature ends with ::
signature_owner = child.astext()[:-2]
elif isinstance(child, addnodes.desc_name):
name = child.astext()
break
# Lookup the object in the Doxygen index
try:
compound, = index.xpath(
'descendant::compound[(not($owner) or name[text() = $owner]) and descendant::name[text() = $name]][1]',
owner=signature_owner or owner,
name=name)
except ValueError:
continue
filename = compound.get('refid') + '.xml'
if filename not in cache:
cache[filename] = etree.parse('xml/' + filename)
# An enumvalue has no location
memberdef, = cache[filename].xpath(
'descendant::compounddef[compoundname[text() = $name]]', name=name) or cache[filename].xpath(
'descendant::memberdef[name[text() = $name] | enumvalue[name[text() = $name]]]', name=name)
# Append the link after the object's signature.
# Get the source file and line number from Doxygen and use
# them to construct the link.
location = memberdef.find('location')
filename = path.basename(location.get('file'))
# Declarations have no bodystart
line = location.get('bodystart') or location.get('line')
emphasis = nodes.emphasis('', ' ' + filename + ' line ' + line)
# Use a relative link if the output is HTML, otherwise fall
# back on an absolute link to Read the Docs. I haven't
# figured out how to get the page name for e.g. a struct
# from the XML files so ape Doxygen escapeCharsInString()
# instead.
refuri = 'api/' + escape(filename) + '_source.html#l' + line.rjust(5, '0')
if self.app.builder.name == 'html':
refuri = osutil.relative_uri(self.app.builder.get_target_uri(self.docname), refuri)
else:
refuri = 'http://docs.trafficserver.apache.org/en/latest/' + refuri
reference = nodes.reference(
'', '', emphasis, classes=['viewcode-link'], reftitle='Source code', refuri=refuri)
desc_child += reference
# Style the links
self.has_link = True
else:
self.traverse(desc_child, name)
else:
self.traverse(child, owner)