Improve index entries
This commit adds additional index entries for IP ranges and IP address references.
This commit is contained in:
parent
48488386d3
commit
39f62dc843
1 changed files with 21 additions and 8 deletions
|
@ -39,8 +39,9 @@ class IPXRefRole(XRefRole):
|
|||
"""
|
||||
Cross referencing role for the IP domain.
|
||||
"""
|
||||
def __init__(self, method, **kwargs):
|
||||
def __init__(self, method, index_type, **kwargs):
|
||||
self.method = method
|
||||
self.index_type = index_type
|
||||
innernodeclass=None
|
||||
if method in ('v4', 'v6'):
|
||||
innernodeclass = ip_node
|
||||
|
@ -58,8 +59,13 @@ class IPXRefRole(XRefRole):
|
|||
indexnode = addnodes.index()
|
||||
targetid = 'index-%s' % env.new_serialno('index')
|
||||
targetnode = nodes.target('', '', ids=[targetid])
|
||||
idxtext = "%s; %s" % (node.astext(), env.docname)
|
||||
indexnode['entries'] = [('single', idxtext, targetid, '', None)]
|
||||
doctitle = document.traverse(nodes.title)[0].astext()
|
||||
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], []
|
||||
except KeyError as e:
|
||||
return [node], [e.args[0]]
|
||||
|
@ -93,8 +99,15 @@ class IPRange(Directive):
|
|||
self.rangespec = self.arguments[0]
|
||||
node = nodes.section()
|
||||
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=[
|
||||
('single', self.get_index_text(), name, '')])
|
||||
('single', idx_text, name, ''),
|
||||
('single', self.get_index_text(), name, '')
|
||||
])
|
||||
|
||||
if self.content:
|
||||
contentnode = nodes.paragraph('')
|
||||
|
@ -148,10 +161,10 @@ class IPDomain(Domain):
|
|||
}
|
||||
|
||||
roles = {
|
||||
'v4': IPXRefRole('v4'),
|
||||
'v6': IPXRefRole('v6'),
|
||||
'v4range': IPXRefRole('v4range'),
|
||||
'v6range': IPXRefRole('v6range'),
|
||||
'v4': IPXRefRole('v4', l_('IPv4 address')),
|
||||
'v6': IPXRefRole('v6', l_('IPv6 address')),
|
||||
'v4range': IPXRefRole('v4range', l_('IPv4 range')),
|
||||
'v6range': IPXRefRole('v6range', l_('IPv6 range')),
|
||||
}
|
||||
|
||||
initial_data = {
|
||||
|
|
Loading…
Reference in a new issue