From 3c32d8c78da86cc2c182ae41e70420bed9ff89ee Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Tue, 29 Jun 2021 15:22:22 +0900 Subject: [PATCH] Ensure stable IDs for dfn refs in domintro sections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change ensures that dfn references/links inside sections which follow the class=domintro convention are output with IDs ending with “-dev” — and most likely, without any additional ①, ②, etc., suffix. Otherwise, without this change, dfn references/links inside class=domintro sections are output with IDs of the form “ref-foo-①”, etc. — just as the IDs output for such references/links outside of class=domintro sections. So this change helps make it likely that dfn references/links inside class=domintro sections end up with stable IDs useful for referencing from MDN and other places — rather than “ref-foo-②”, etc. IDs that might change if some new reference to a term is added to a spec somewhere preceding a class=domintro section where the term is referenced. Relates to https://github.com/mdn/browser-compat-data/issues/11088 --- bikeshed/dfnpanels.py | 5 ++++- bikeshed/h/dom.py | 2 +- bikeshed/unsortedJunk.py | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bikeshed/dfnpanels.py b/bikeshed/dfnpanels.py index c9259e8443..117977a440 100644 --- a/bikeshed/dfnpanels.py +++ b/bikeshed/dfnpanels.py @@ -45,7 +45,10 @@ def addDfnPanels(doc, dfns): for i, el in enumerate(els): refID = el.get("id") if refID is None: - refID = f"ref-for-{id}" + if hasAncestor(el, lambda x: hasClass(x, "domintro")): + refID = f"{id}-dev" + else: + refID = f"ref-for-{id}" el.set("id", safeID(doc, refID)) if i == 0: appendChild( diff --git a/bikeshed/h/dom.py b/bikeshed/h/dom.py index 9e5ab13f4c..e32ab440b6 100644 --- a/bikeshed/h/dom.py +++ b/bikeshed/h/dom.py @@ -803,7 +803,7 @@ def dedupIDs(doc): continue if el.get("data-silently-dedup") is not None: warnAboutDupes = False - if dupeId.startswith("ref-for-"): + if dupeId.startswith("ref-for-") or dupeId.endswith("-dev"): warnAboutDupes = False # Try to de-dup the id by appending an integer after it. if warnAboutDupes: diff --git a/bikeshed/unsortedJunk.py b/bikeshed/unsortedJunk.py index 7e1b5e3af0..cb56b13836 100644 --- a/bikeshed/unsortedJunk.py +++ b/bikeshed/unsortedJunk.py @@ -1072,7 +1072,10 @@ def decorateAutolink(doc, el, linkType, linkText, ref): if el.get("id") is None: _, _, id = ref.url.partition("#") if id: - el.set("id", f"ref-for-{id}") + if hasAncestor(el, lambda x: hasClass(x, "domintro")): + el.set("id", f"{id}-dev") + else: + el.set("id", f"ref-for-{id}") el.set("data-silently-dedup", "") # Get all the values that the type expands to, add it as a title.