Skip to content

Link to the single-page HTML spec instead of multipage - #63375

Closed
zcorpan wants to merge 1 commit into
masterfrom
zcorpan/single-page-html-links
Closed

zcorpan wants to merge 1 commit into
masterfrom
zcorpan/single-page-html-links

Conversation

@zcorpan

@zcorpan zcorpan commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Part of #63371.

Part of #63371.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zcorpan
zcorpan force-pushed the zcorpan/single-page-html-links branch from 2b384c6 to 28b4902 Compare October 7, 2026 22:23
@zcorpan zcorpan changed the title Link to the single-page HTML spec and lint against multipage links Link to the single-page HTML spec instead of multipage Oct 7, 2026
@zcorpan

zcorpan commented Oct 7, 2026

Copy link
Copy Markdown
Member Author
Rewrite script, generated by Claude (not checked in):

Run from the repo root:

curl -sSLO https://html.spec.whatwg.org/multipage/fragment-links.json
python3 rewrite.py fragment-links.json

scan.py lists links without a fragment, which rewrite.py maps from page name to section id. If a page isn't in fragment-links.json, rewrite.py prints "unknown page" and skips the file; add it to special.

scan.py

import re, subprocess, collections
RE = re.compile(r"(https?://)?html\.spec\.whatwg\.org/multipage(?:/multipage)?(?:/([A-Za-z0-9._-]*))?(#[^\s\"'<>`]*)?")
files = subprocess.check_output(["git", "grep", "-l", "html.spec.whatwg.org/multipage", "--", ":!tools/lint"], text=True).split("\n")
c = collections.Counter()
for f in filter(None, files):
    s = open(f, encoding="utf-8", errors="surrogateescape").read()
    for m in RE.finditer(s):
        if not m.group(3):
            c[(m.group(2), f)] += 1
for k, v in sorted(c.items()):
    print(v, k)

rewrite.py

import json, re, subprocess, sys
ids = json.load(open(sys.argv[1]))
special = {"": "", "index": "", "popover": "#the-popover-attribute",
           "structured-data": "#safe-passing-of-structured-data"}
RE = re.compile(r"html\.spec\.whatwg\.org/multipage(?:/multipage)?(?:/([A-Za-z0-9-]*)(?:\.html?)?)?/?(?=(#?))")

def repl(m):
    page = m.group(1) or ""
    if m.group(2):
        return "html.spec.whatwg.org/"
    if page in special:
        return "html.spec.whatwg.org/" + special[page]
    if page in ids:
        return "html.spec.whatwg.org/#" + page
    raise Exception(f"unknown page {page!r}")

files = subprocess.check_output(["git", "grep", "-l", "html.spec.whatwg.org/multipage", "--", ":!tools/lint"], text=True).split("\n")
for f in filter(None, files):
    with open(f, "rb") as fh:
        s = fh.read().decode("utf-8", "surrogateescape")
    try:
        t = RE.sub(repl, s)
    except Exception as e:
        print(f, e)
        continue
    if t != s:
        with open(f, "wb") as fh:
            fh.write(t.encode("utf-8", "surrogateescape"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants