Skip to content

Commit

Permalink
Ensure stable IDs for dfn refs in domintro sections
Browse files Browse the repository at this point in the history
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 mdn/browser-compat-data#11088
  • Loading branch information
sideshowbarker committed Jun 29, 2021
1 parent ff16a98 commit 3c32d8c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bikeshed/dfnpanels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion bikeshed/h/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion bikeshed/unsortedJunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3c32d8c

Please sign in to comment.