Improve index entries

This commit adds additional index entries for IP ranges and IP address
references.
This commit is contained in:
Jan Dittberner 2016-04-25 00:46:32 +02:00
parent 48488386d3
commit 39f62dc843

View file

@ -39,8 +39,9 @@ class IPXRefRole(XRefRole):
""" """
Cross referencing role for the IP domain. Cross referencing role for the IP domain.
""" """
def __init__(self, method, **kwargs): def __init__(self, method, index_type, **kwargs):
self.method = method self.method = method
self.index_type = index_type
innernodeclass=None innernodeclass=None
if method in ('v4', 'v6'): if method in ('v4', 'v6'):
innernodeclass = ip_node innernodeclass = ip_node
@ -58,8 +59,13 @@ class IPXRefRole(XRefRole):
indexnode = addnodes.index() indexnode = addnodes.index()
targetid = 'index-%s' % env.new_serialno('index') targetid = 'index-%s' % env.new_serialno('index')
targetnode = nodes.target('', '', ids=[targetid]) targetnode = nodes.target('', '', ids=[targetid])
idxtext = "%s; %s" % (node.astext(), env.docname) doctitle = document.traverse(nodes.title)[0].astext()
indexnode['entries'] = [('single', idxtext, targetid, '', None)] idxtext = "%s; %s" % (node.astext(), doctitle)
idxtext2 = "%s; %s" % (self.index_type, node.astext())
indexnode['entries'] = [
('single', idxtext, targetid, '', None),
('single', idxtext2, targetid, '', None),
]
return [indexnode, targetnode, node], [] return [indexnode, targetnode, node], []
except KeyError as e: except KeyError as e:
return [node], [e.args[0]] return [node], [e.args[0]]
@ -93,8 +99,15 @@ class IPRange(Directive):
self.rangespec = self.arguments[0] self.rangespec = self.arguments[0]
node = nodes.section() node = nodes.section()
name = self.handle_rangespec(node) name = self.handle_rangespec(node)
if self.env.docname in self.env.titles:
doctitle = self.env.titles[self.env.docname]
else:
doctitle = self.state.document.traverse(nodes.title)[0].astext()
idx_text = "%s; %s" % (self.rangespec, doctitle)
self.indexnode = addnodes.index(entries=[ self.indexnode = addnodes.index(entries=[
('single', self.get_index_text(), name, '')]) ('single', idx_text, name, ''),
('single', self.get_index_text(), name, '')
])
if self.content: if self.content:
contentnode = nodes.paragraph('') contentnode = nodes.paragraph('')
@ -148,10 +161,10 @@ class IPDomain(Domain):
} }
roles = { roles = {
'v4': IPXRefRole('v4'), 'v4': IPXRefRole('v4', l_('IPv4 address')),
'v6': IPXRefRole('v6'), 'v6': IPXRefRole('v6', l_('IPv6 address')),
'v4range': IPXRefRole('v4range'), 'v4range': IPXRefRole('v4range', l_('IPv4 range')),
'v6range': IPXRefRole('v6range'), 'v6range': IPXRefRole('v6range', l_('IPv6 range')),
} }
initial_data = { initial_data = {