diff --git a/tools/check_links.py b/tools/check_links.py index 523b0f86..717596f7 100755 --- a/tools/check_links.py +++ b/tools/check_links.py @@ -11,13 +11,15 @@ from urllib.parse import unquote, urldefrag, urlparse # minified pages drop the quotes around simple attribute values ATTR = re.compile(r'\b(?:href|src)=(?:"([^"]*)"|\'([^\']*)\'|([^\s>"\']+))', re.I) +# code samples show markup, they do not link (escaped HTML in a
would look like attributes)
+PRE = re.compile(r'', re.I | re.S)
def main():
root = Path(sys.argv[1] if len(sys.argv) > 1 else "public").resolve()
broken, checked = {}, 0
for page in sorted(root.rglob("*.html")):
- text = page.read_text(encoding="utf-8", errors="replace")
+ text = PRE.sub("", page.read_text(encoding="utf-8", errors="replace"))
for url in {a or b or c for a, b, c in ATTR.findall(text)}:
url = urldefrag(html.unescape(url))[0]
parsed = urlparse(url)