Add handling for missing references

This commit is contained in:
Jan Dittberner 2016-04-24 15:04:07 +02:00
parent 0012b495b3
commit 334968385b

View file

@ -39,12 +39,15 @@ class IPXRefRole(XRefRole):
return title, target return title, target
def result_nodes(self, document, env, node, is_ref): def result_nodes(self, document, env, node, is_ref):
indexnode = addnodes.index() try:
targetid = 'index-%s' % env.new_serialno('index') indexnode = addnodes.index()
targetnode = nodes.target('', '', ids=[targetid]) targetid = 'index-%s' % env.new_serialno('index')
idxtext = "%s; %s" % (node.astext(), env.docname) targetnode = nodes.target('', '', ids=[targetid])
indexnode['entries'] = [('single', idxtext, targetid, '', None)] idxtext = "%s; %s" % (node.astext(), env.docname)
return [indexnode, targetnode, node], [] indexnode['entries'] = [('single', idxtext, targetid, '', None)]
return [indexnode, targetnode, node], []
except KeyError as e:
return [node], [e.args[0]]
class IPObject(ObjectDescription): class IPObject(ObjectDescription):
@ -166,7 +169,7 @@ class IPDomain(Domain):
if role is None: if role is None:
return None return None
resnode = role.result_nodes(env.get_doctree(fromdocname), resnode = role.result_nodes(env.get_doctree(fromdocname),
env, node, None)[0][0] env, node, True)[0][0]
if isinstance(resnode, addnodes.pending_xref): if isinstance(resnode, addnodes.pending_xref):
text = node[0][0] text = node[0][0]
reporter = env.get_doctree(fromdocname).reporter reporter = env.get_doctree(fromdocname).reporter