links_and_dests.py: fix false positive "Missing link target" errors for links into rendered BIPs.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Daira Hopwood 2021-12-03 14:54:22 +00:00
parent c3dac4e458
commit ea53ac9d6f
1 changed files with 5 additions and 1 deletions

View File

@ -62,6 +62,10 @@ def get_links_and_destinations_from_html(f):
for link in soup.find_all(id=True):
dests.add(link['id'])
# GitHub's rendering of .mediawiki files puts 'id="user-content-<ANCHOR>"' in the source
# and dynamically creates a corresponding link #<ANCHOR>.
if link['id'].startswith("user-content-"):
dests.add(link['id'][13:])
internal.difference_update(['#' + d for d in dests]) # ignore internal links satisfied by a dest
links.update(internal)
@ -180,7 +184,7 @@ def main(args):
if content is not None:
if fragment:
if dests is None:
if content_type == 'text/html':
if content_type in ('text/html', 'application/xhtml+xml'):
(_, dests) = get_links_and_destinations_from_html(BytesIO(content))
elif content_type == 'application/pdf':
(_, dests) = get_links_and_destinations_from_pdf(BytesIO(content))