in tools/boardminutes2html.py [0:0]
def add_anchor(current_s, line, links, info):
"""Add anchors"""
# main section
mat = re.match(r'^([ \d]\d)(\. .+)', line)
if mat:
sect = mat.group(1)
off = ''
if sect.startswith(' '):
off = ''
sid = sect.replace(' ','')
rest = mat.group(2)
sname = f"section-{sid}"
line = f'{off}<a class="selflink" id="{sname}" href="#{sname}">{sid}{rest}</a>\n'
links[sname] = rest.lstrip('. ')
# flag when in committee reports
if 'Committee Reports' in rest:
info['crsection'] = sid
else:
info.pop('crsection', None)
return sid, line # return the updated section number
# subsections
mat = re.match(r'^( {3,4})([A-Z]+)(\. .+)', line)
if mat:
off = mat.group(1)
sect = mat.group(2)
sid = current_s + sect.lstrip(' ')
sname = f"section-{sid}"
rest = mat.group(3)
line = f'{off}<a class="selflink" id="{sname}" href="#{sname}">{sect}{rest}</a>\n'
links[sname] = rest.lstrip('. ')
return current_s, line
# Attachments
mat = re.match(r'^Attachment (\w+)(: .+)', line)
if mat:
sect = mat.group(1)
sname = 'attachment-' + sect
rest = mat.group(2)
info['sname'] = rest
line = f'<a class="selflink" id="{sname}" href="#{sname}">Attachment {sect}{rest}</a>\n'
links[sname] = rest.lstrip(':')
return current_s, line
# Links to attachments
mat = re.match(r'^ +(See Attachment (\w+))', line)
if mat:
ref = mat.group(1)
sect = mat.group(2)
line = line.replace(ref, f'<a href="#attachment-{sect}">{ref}</a>')
# drop link to CR section if there is an attachment
crsect = info.get('crsection')
if crsect:
links.pop(f'section-{crsect}{sect}')
return current_s, line
# board minutes
mat = re.search(r' (board_minutes_(\d\d\d\d)_\d\d_\d\d.txt)', line)
if mat:
minutes = mat.group(1)
year = mat.group(2)
line = line.replace(minutes, f'<a href="{MINUTES}{year}/{minutes}">{minutes}</a>')
return current_s, line
# external URLs TODO: tighten matching ..
mat = re.search(r'(https?://[^\s,)]+)', line)
if mat:
url = mat.group(1).rstrip(".")
line = line.replace(url, f'<a href="{url}">{url}</a>')
return current_s, line
# Podling ToC?
# [Podling](#podling)
mat = re.match(r'\[[^]]+\]\((#[^)]+)\)', line)
if mat:
anchor = mat.group(1)
line = line.replace(anchor, f'<a href="{pod_anchor(anchor)}">{anchor}</a>')
return current_s, line
# we are in a podling report
if info['podhdr'] and line.strip() != '':
info['podhdr'] = False
pod = line.lstrip('# ').strip()
anchor = pod_anchor(pod)
if not pod.startswith('---'): # --- indicates end of podlings
line = f'<a class="selflink" id="{anchor}" href="#{anchor}">{line.strip()}</a>\n'
links[anchor] = "-- " + pod
return current_s, line
# Start of a podling section?
if line.strip() == '--------------------' and 'Incubator Project' in info['sname']:
info['podhdr'] = True
# anything else
return current_s, line