Add handling for multiple IP occurrences
This commit adds handling of multiple occurrences of the same IP address in one or more pages.
This commit is contained in:
parent
f812a91310
commit
dd419f4ae6
3 changed files with 44 additions and 21 deletions
|
@ -234,8 +234,8 @@ def process_ips(app, doctree):
|
||||||
node.replace_self(replacement)
|
node.replace_self(replacement)
|
||||||
|
|
||||||
|
|
||||||
def sort_ip_info(item):
|
def sort_ip(item):
|
||||||
return Network(item['ip']).ip
|
return Network(item).ip
|
||||||
|
|
||||||
|
|
||||||
def create_table_row(rowdata):
|
def create_table_row(rowdata):
|
||||||
|
@ -257,9 +257,14 @@ def process_ip_nodes(app, doctree, fromdocname):
|
||||||
for node in doctree.traverse(ip_range):
|
for node in doctree.traverse(ip_range):
|
||||||
content = []
|
content = []
|
||||||
net = Network(node['rangespec'])
|
net = Network(node['rangespec'])
|
||||||
ips = [ip_info for ip_info in
|
ips = {}
|
||||||
sorted(domaindata['ips'], key=sort_ip_info)
|
for key, value in [
|
||||||
if ip_info['ip'] in net]
|
(ip_info['ip'], ip_info) for ip_info in
|
||||||
|
domaindata['ips'] if ip_info['ip'] in net
|
||||||
|
]:
|
||||||
|
addrlist = ips.get(key, [])
|
||||||
|
addrlist.append(value)
|
||||||
|
ips[key] = addrlist
|
||||||
if ips:
|
if ips:
|
||||||
table = nodes.table()
|
table = nodes.table()
|
||||||
tgroup = nodes.tgroup(cols=len(header))
|
tgroup = nodes.tgroup(cols=len(header))
|
||||||
|
@ -272,24 +277,37 @@ def process_ip_nodes(app, doctree, fromdocname):
|
||||||
nodes.paragraph(text=label) for label in header])
|
nodes.paragraph(text=label) for label in header])
|
||||||
tbody = nodes.tbody()
|
tbody = nodes.tbody()
|
||||||
tgroup += tbody
|
tgroup += tbody
|
||||||
for ip_info in ips:
|
for ip, ip_info in [
|
||||||
|
(ip, ips[ip]) for ip in sorted(ips, key=sort_ip)
|
||||||
|
]:
|
||||||
para = nodes.paragraph()
|
para = nodes.paragraph()
|
||||||
para += nodes.literal('', ip_info['ip'])
|
para += nodes.literal('', ip)
|
||||||
ids = ip_object_anchor(ip_info['typ'], ip_info['ip'])
|
|
||||||
para['ids'].append(ids)
|
|
||||||
|
|
||||||
domaindata[ip_info['typ']][ids] = (fromdocname, '')
|
|
||||||
newnode = nodes.reference('', '', internal=True)
|
|
||||||
try:
|
|
||||||
newnode['refuri'] = app.builder.get_relative_uri(
|
|
||||||
fromdocname, ip_info['docname'])
|
|
||||||
except NoUri:
|
|
||||||
pass
|
|
||||||
title = env.titles[ip_info['docname']]
|
|
||||||
innernode = nodes.Text(title.astext())
|
|
||||||
newnode.append(innernode)
|
|
||||||
refnode = nodes.paragraph()
|
refnode = nodes.paragraph()
|
||||||
refnode.append(newnode)
|
refuris = set()
|
||||||
|
refnodes = []
|
||||||
|
for item in ip_info:
|
||||||
|
ids = ip_object_anchor(item['typ'], item['ip'])
|
||||||
|
if ids not in para['ids']:
|
||||||
|
para['ids'].append(ids)
|
||||||
|
|
||||||
|
domaindata[item['typ']][ids] = (fromdocname, '')
|
||||||
|
newnode = nodes.reference('', '', internal=True)
|
||||||
|
try:
|
||||||
|
newnode['refuri'] = app.builder.get_relative_uri(
|
||||||
|
fromdocname, item['docname'])
|
||||||
|
if newnode['refuri'] in refuris:
|
||||||
|
continue
|
||||||
|
refuris.add(newnode['refuri'])
|
||||||
|
except NoUri:
|
||||||
|
pass
|
||||||
|
title = env.titles[item['docname']]
|
||||||
|
innernode = nodes.Text(title.astext())
|
||||||
|
newnode.append(innernode)
|
||||||
|
refnodes.append(newnode)
|
||||||
|
for count in range(len(refnodes)):
|
||||||
|
refnode.append(refnodes[count])
|
||||||
|
if count < len(refnodes) - 1:
|
||||||
|
refnode.append(nodes.Text(", "))
|
||||||
tbody += create_table_row([para, refnode])
|
tbody += create_table_row([para, refnode])
|
||||||
content.append(table)
|
content.append(table)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -13,6 +13,7 @@ Contents:
|
||||||
|
|
||||||
testpage1
|
testpage1
|
||||||
testpage2
|
testpage2
|
||||||
|
testpage3
|
||||||
|
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
|
|
4
tests/root/testpage3.rst
Normal file
4
tests/root/testpage3.rst
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Test page 3
|
||||||
|
===========
|
||||||
|
|
||||||
|
This page contains :ip:v6:`2001:dead:beef::1` like :doc:`testpage2` does.
|
Loading…
Reference in a new issue