Skip to content

Commit fdd5936

Browse files
committed
Localize all the 'register that a biblio reference exists' code, and make section links use it. Fixes #2280
1 parent 1c42446 commit fdd5936

File tree

207 files changed

+1367
-2088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

207 files changed

+1367
-2088
lines changed

bikeshed/Spec.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ def processDocument(self):
244244
u.formatArgumentdefTables(self)
245245
u.formatElementdefTables(self)
246246
u.processAutolinks(self)
247+
u.fixInterDocumentReferences(self)
247248
biblio.dedupBiblioReferences(self)
248-
u.verifyUsageOfAllLocalBiblios(self)
249249
caniuse.addCanIUsePanels(self)
250250
boilerplate.addIndexSection(self)
251251
boilerplate.addExplicitIndexes(self)
@@ -269,6 +269,7 @@ def processDocument(self):
269269
fingerprinting.addTrackingVector(self)
270270
u.fixIntraDocumentReferences(self)
271271
u.fixInterDocumentReferences(self)
272+
u.verifyUsageOfAllLocalBiblios(self)
272273
u.removeMultipleLinks(self)
273274
u.forceCrossorigin(self)
274275
lint.brokenLinks(self)

bikeshed/biblio.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,4 +525,4 @@ def isShepherdRef(ref):
525525
if keys["shepherd"] in doc.externalRefsUsed:
526526
for k, v in list(doc.externalRefsUsed[keys["shepherd"]].items()):
527527
doc.externalRefsUsed[keys["specref"]][k] = v
528-
del doc.externalRefsUsed[keys["shepherd"]]
528+
del doc.externalRefsUsed[keys["shepherd"]]

bikeshed/unsortedJunk.py

+42-31
Original file line numberDiff line numberDiff line change
@@ -445,30 +445,31 @@ def fixInterDocumentReferences(doc: "t.SpecType"):
445445
)
446446

447447

448-
def fillInterDocumentReferenceFromShepherd(doc: "t.SpecType", el, spec, section):
449-
specData = doc.refs.fetchHeadings(spec)
450-
if section in specData:
451-
heading = specData[section]
448+
def fillInterDocumentReferenceFromShepherd(doc: "t.SpecType", el, specName, section):
449+
headingData = doc.refs.fetchHeadings(specName)
450+
if section in headingData:
451+
heading = headingData[section]
452452
else:
453453
m.die(
454-
f"Couldn't find section '{section}' in spec '{spec}':\n{h.outerHTML(el)}",
454+
f"Couldn't find section '{section}' in spec '{specName}':\n{h.outerHTML(el)}",
455455
el=el,
456456
)
457457
return
458458
if isinstance(heading, list):
459459
# Multipage spec
460460
if len(heading) == 1:
461461
# only one heading of this name, no worries
462-
heading = specData[heading[0]]
462+
heading = headingData[heading[0]]
463463
else:
464464
# multiple headings of this id, user needs to disambiguate
465465
m.die(
466-
f"Multiple headings with id '{section}' for spec '{spec}'. Please specify:\n"
467-
+ "\n".join(" [[{}]]".format(spec + x) for x in heading),
466+
f"Multiple headings with id '{section}' for spec '{specName}'. Please specify:\n"
467+
+ "\n".join(f" [[{specName + x}]]" for x in heading),
468468
el=el,
469469
)
470470
return
471471
if doc.md.status == "current":
472+
# FIXME: doc.md.status is not these values
472473
if "current" in heading:
473474
heading = heading["current"]
474475
else:
@@ -485,6 +486,11 @@ def fillInterDocumentReferenceFromShepherd(doc: "t.SpecType", el, spec, section)
485486
h.appendChild(el, " §\u202f{number} {text}".format(**heading))
486487
h.removeAttr(el, "data-link-spec", "spec-section")
487488

489+
# Mark this as a used biblio ref
490+
specData = doc.refs.specs[specName]
491+
bib = biblio.SpecBasedBiblioEntry(specData)
492+
registerBiblioUsage(doc, bib, el=el)
493+
488494

489495
def fillInterDocumentReferenceFromSpecref(doc: "t.SpecType", el, spec, section):
490496
bib = doc.refs.getBiblioRef(spec)
@@ -497,6 +503,9 @@ def fillInterDocumentReferenceFromSpecref(doc: "t.SpecType", el, spec, section):
497503
el.text = bib.title + " §\u202f" + section[1:]
498504
h.removeAttr(el, "data-link-spec", "spec-section")
499505

506+
# Mark this as a used biblio ref
507+
registerBiblioUsage(doc, bib, el=el)
508+
500509

501510
def processDfns(doc: "t.SpecType"):
502511
dfns = h.findAll(config.dfnElementsSelector, doc)
@@ -767,17 +776,6 @@ def classifyLink(el):
767776
def processBiblioLinks(doc: "t.SpecType"):
768777
biblioLinks = h.findAll("a[data-link-type='biblio']", doc)
769778
for el in biblioLinks:
770-
biblioType = el.get("data-biblio-type")
771-
if biblioType == "normative":
772-
storage = doc.normativeRefs
773-
elif biblioType == "informative":
774-
storage = doc.informativeRefs
775-
else:
776-
m.die(
777-
f"Unknown data-biblio-type value '{biblioType}' on {h.outerHTML(el)}. Only 'normative' and 'informative' allowed.",
778-
el=el,
779-
)
780-
continue
781779

782780
linkText = determineLinkText(el)
783781
if linkText[0] == "[" and linkText[-1] == "]":
@@ -828,7 +826,7 @@ def processBiblioLinks(doc: "t.SpecType"):
828826
doc.refs.preferredBiblioNames[ref.linkText] = linkText
829827
# Use it on the current ref. Future ones will use the preferred name automatically.
830828
ref.linkText = linkText
831-
storage[ref.linkText] = ref
829+
registerBiblioUsage(doc, ref, el=el, type=el.get("data-biblio-type"))
832830

833831
id = config.simplifyText(ref.linkText)
834832
el.set("href", "#biblio-" + id)
@@ -853,8 +851,8 @@ def verifyUsageOfAllLocalBiblios(doc: "t.SpecType"):
853851
were used in the spec,
854852
so you can remove entries when they're no longer necessary.
855853
"""
856-
usedBiblioKeys = {x.lower() for x in list(doc.normativeRefs.keys()) + list(doc.informativeRefs.keys())}
857-
localBiblios = [b["linkText"].lower() for bs in doc.refs.biblios.values() for b in bs if b["order"] == 1]
854+
usedBiblioKeys = {x.upper() for x in list(doc.normativeRefs.keys()) + list(doc.informativeRefs.keys())}
855+
localBiblios = [b["linkText"].upper() for bs in doc.refs.biblios.values() for b in bs if b["order"] == 1]
858856
unusedBiblioKeys = []
859857
for b in localBiblios:
860858
if b not in usedBiblioKeys:
@@ -927,15 +925,10 @@ def processAutolinks(doc: "t.SpecType"):
927925
# rather than checking `status == "local"`, as "local" refs include
928926
# those defined in `<pre class="anchor">` datablocks, which we do
929927
# want to capture here.
930-
if ref and ref.spec and doc.refs.spec and ref.spec.lower() != doc.refs.spec.lower():
931-
spec = ref.spec.lower()
928+
if ref and ref.spec and doc.refs.spec and ref.spec.upper() != doc.refs.spec.upper():
929+
spec = ref.spec.upper()
932930
key = ref.for_[0] if ref.for_ else ""
933931

934-
if h.isNormative(el, doc):
935-
biblioStorage = doc.normativeRefs
936-
else:
937-
biblioStorage = doc.informativeRefs
938-
939932
# If the ref is from an anchor block, it knows what it's doing.
940933
# Don't follow obsoletion chains.
941934
allowObsolete = ref.status == "anchor-block"
@@ -948,8 +941,8 @@ def processAutolinks(doc: "t.SpecType"):
948941
allowObsolete=allowObsolete,
949942
)
950943
if biblioRef:
951-
biblioStorage[biblioRef.linkText] = biblioRef
952-
spec = biblioRef.linkText.lower()
944+
spec = biblioRef.linkText.upper()
945+
registerBiblioUsage(doc, biblioRef, el=el)
953946
doc.externalRefsUsed[spec]["_biblio"] = biblioRef
954947
doc.externalRefsUsed[spec][ref.text][key] = ref
955948

@@ -967,6 +960,24 @@ def processAutolinks(doc: "t.SpecType"):
967960
h.dedupIDs(doc)
968961

969962

963+
def registerBiblioUsage(
964+
doc: "t.SpecType", ref: biblio.BiblioEntry, el: t.ElementT, type: t.Optional[str] = None
965+
) -> None:
966+
if type is None:
967+
if h.isNormative(el, doc):
968+
type = "normative"
969+
else:
970+
type = "informative"
971+
if type == "normative":
972+
biblioStorage = doc.normativeRefs
973+
elif type == "informative":
974+
biblioStorage = doc.informativeRefs
975+
else:
976+
m.die(f"Unknown biblio type {type}.", el=el)
977+
return
978+
biblioStorage[ref.linkText.upper()] = ref
979+
980+
970981
def decorateAutolink(doc: "t.SpecType", el, linkType, linkText, ref):
971982
# Add additional effects to autolinks.
972983
if doc.md.slimBuildArtifact:

tests/github/WICG/aom/spec/custom-element-semantics.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -1108,13 +1108,13 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
11081108
<h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span class="content">Terms defined by reference</span><a class="self-link" href="#index-defined-elsewhere"></a></h3>
11091109
<ul class="index">
11101110
<li>
1111-
<a data-link-type="biblio">[aria]</a> defines the following terms:
1111+
<a data-link-type="biblio">[ARIA]</a> defines the following terms:
11121112
<ul>
11131113
<li><span class="dfn-paneled" id="term-for-idl-def-accessibilityrole">AccessibilityRole</span>
11141114
<li><span class="dfn-paneled" id="term-for-idl-def-ariaattributes">AriaAttributes</span>
11151115
</ul>
11161116
<li>
1117-
<a data-link-type="biblio">[core-aam]</a> defines the following terms:
1117+
<a data-link-type="biblio">[CORE-AAM]</a> defines the following terms:
11181118
<ul>
11191119
<li><span class="dfn-paneled" id="term-for-dfn-accessibility-tree">accessibility tree</span>
11201120
<li><span class="dfn-paneled" id="term-for-dfn-accessible-object">accessible object</span>
@@ -1139,7 +1139,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
11391139
<li><span class="dfn-paneled" id="term-for-custom-element-definition①">defined</span>
11401140
</ul>
11411141
<li>
1142-
<a data-link-type="biblio">[html-aam]</a> defines the following terms:
1142+
<a data-link-type="biblio">[HTML-AAM]</a> defines the following terms:
11431143
<ul>
11441144
<li><span class="dfn-paneled" id="term-for-details-id-17">role of button</span>
11451145
</ul>
@@ -1161,6 +1161,8 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
11611161
<dd>Anne van Kesteren. <a href="https://dom.spec.whatwg.org/"><cite>DOM Standard</cite></a>. Living Standard. URL: <a href="https://dom.spec.whatwg.org/">https://dom.spec.whatwg.org/</a>
11621162
<dt id="biblio-html">[HTML]
11631163
<dd>Anne van Kesteren; et al. <a href="https://html.spec.whatwg.org/multipage/"><cite>HTML Standard</cite></a>. Living Standard. URL: <a href="https://html.spec.whatwg.org/multipage/">https://html.spec.whatwg.org/multipage/</a>
1164+
<dt id="biblio-html-aam-10">[HTML-AAM-1.0]
1165+
<dd>Steve Faulkner; et al. <a href="https://www.w3.org/TR/html-aam-1.0/"><cite>HTML Accessibility API Mappings 1.0</cite></a>. 17 August 2020. WD. URL: <a href="https://www.w3.org/TR/html-aam-1.0/">https://www.w3.org/TR/html-aam-1.0/</a>
11641166
<dt id="biblio-rfc2119">[RFC2119]
11651167
<dd>S. Bradner. <a href="https://datatracker.ietf.org/doc/html/rfc2119"><cite>Key words for use in RFCs to Indicate Requirement Levels</cite></a>. March 1997. Best Current Practice. URL: <a href="https://datatracker.ietf.org/doc/html/rfc2119">https://datatracker.ietf.org/doc/html/rfc2119</a>
11661168
<dt id="biblio-webidl">[WebIDL]

tests/github/WICG/app-history/spec.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
23962396
<li><span class="dfn-paneled" id="term-for-concept-url-serializer">url serializer</span>
23972397
</ul>
23982398
<li>
2399-
<a data-link-type="biblio">[uuid]</a> defines the following terms:
2399+
<a data-link-type="biblio">[UUID]</a> defines the following terms:
24002400
<ul>
24012401
<li><span class="dfn-paneled" id="term-for-dfn-generate-a-random-uuid">generate a random uuid</span>
24022402
</ul>
@@ -2455,6 +2455,8 @@ <h3 class="no-num no-ref heading settled" id="informative"><span class="content"
24552455
<dd>Mike West. <a href="https://w3c.github.io/webappsec-csp/"><cite>Content Security Policy Level 3</cite></a>. URL: <a href="https://w3c.github.io/webappsec-csp/">https://w3c.github.io/webappsec-csp/</a>
24562456
<dt id="biblio-webappsec-fetch-metadata-1">[WEBAPPSEC-FETCH-METADATA-1]
24572457
<dd>Fetch Metadata Request Headers URL: <a href="https://w3c.github.io/webappsec-fetch-metadata/">https://w3c.github.io/webappsec-fetch-metadata/</a>
2458+
<dt id="biblio-webidl①">[WebIDL]
2459+
<dd>Boris Zbarsky. <a href="https://heycam.github.io/webidl/"><cite>Web IDL</cite></a>. URL: <a href="https://heycam.github.io/webidl/">https://heycam.github.io/webidl/</a>
24582460
</dl>
24592461
<h2 class="no-num no-ref heading settled" id="idl-index"><span class="content">IDL Index</span><a class="self-link" href="#idl-index"></a></h2>
24602462
<pre class="idl highlight def"><c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://html.spec.whatwg.org/multipage/window-object.html#window"><c- g>Window</c-></a> {

tests/github/WICG/background-fetch/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
758758
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
759759
<ol class="toc">
760760
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
761+
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
761762
</ol>
762763
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
763764
<li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a>
@@ -3465,6 +3466,11 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
34653466
<dt id="biblio-webidl">[WebIDL]
34663467
<dd>Boris Zbarsky. <a href="https://heycam.github.io/webidl/"><cite>Web IDL</cite></a>. 15 December 2016. ED. URL: <a href="https://heycam.github.io/webidl/">https://heycam.github.io/webidl/</a>
34673468
</dl>
3469+
<h3 class="no-num no-ref heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
3470+
<dl>
3471+
<dt id="biblio-webdriver①">[WebDriver]
3472+
<dd>Simon Stewart; David Burns. <a href="https://www.w3.org/TR/webdriver1/"><cite>WebDriver</cite></a>. 5 June 2018. REC. URL: <a href="https://www.w3.org/TR/webdriver1/">https://www.w3.org/TR/webdriver1/</a>
3473+
</dl>
34683474
<h2 class="no-num no-ref heading settled" id="idl-index"><span class="content">IDL Index</span><a class="self-link" href="#idl-index"></a></h2>
34693475
<pre class="idl highlight def"><c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope"><c- g>ServiceWorkerGlobalScope</c-></a> {
34703476
<c- b>attribute</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler"><c- n>EventHandler</c-></a> <a data-type="EventHandler" href="#dom-serviceworkerglobalscope-onbackgroundfetchsuccess"><code><c- g>onbackgroundfetchsuccess</c-></code></a>;

tests/github/WICG/background-sync/spec/PeriodicBackgroundSync-index.html

+2
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,8 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
17691769
<dd>S. Bradner. <a href="https://datatracker.ietf.org/doc/html/rfc2119"><cite>Key words for use in RFCs to Indicate Requirement Levels</cite></a>. March 1997. Best Current Practice. URL: <a href="https://datatracker.ietf.org/doc/html/rfc2119">https://datatracker.ietf.org/doc/html/rfc2119</a>
17701770
<dt id="biblio-service-workers-1">[SERVICE-WORKERS-1]
17711771
<dd>Alex Russell; et al. <a href="https://www.w3.org/TR/service-workers-1/"><cite>Service Workers 1</cite></a>. 19 November 2019. CR. URL: <a href="https://www.w3.org/TR/service-workers-1/">https://www.w3.org/TR/service-workers-1/</a>
1772+
<dt id="biblio-service-workers-1①">[SERVICE-WORKERS-1]
1773+
<dd>Alex Russell; et al. <a href="https://www.w3.org/TR/service-workers-1/"><cite>Service Workers 1</cite></a>. 19 November 2019. CR. URL: <a href="https://www.w3.org/TR/service-workers-1/">https://www.w3.org/TR/service-workers-1/</a>
17721774
<dt id="biblio-web-background-sync">[WEB-BACKGROUND-SYNC]
17731775
<dd><a href="https://wicg.github.io/background-sync/spec/"><cite>Web Background Synchronization</cite></a>. cg-draft. URL: <a href="https://wicg.github.io/background-sync/spec/">https://wicg.github.io/background-sync/spec/</a>
17741776
<dt id="biblio-webidl">[WebIDL]

tests/github/WICG/background-sync/spec/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
698698
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
699699
<ol class="toc">
700700
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
701+
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
701702
</ol>
702703
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
703704
</ol>
@@ -1359,6 +1360,11 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
13591360
<dt id="biblio-webidl">[WebIDL]
13601361
<dd>Boris Zbarsky. <a href="https://heycam.github.io/webidl/"><cite>Web IDL</cite></a>. 15 December 2016. ED. URL: <a href="https://heycam.github.io/webidl/">https://heycam.github.io/webidl/</a>
13611362
</dl>
1363+
<h3 class="no-num no-ref heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
1364+
<dl>
1365+
<dt id="biblio-service-workers-1①">[SERVICE-WORKERS-1]
1366+
<dd>Alex Russell; et al. <a href="https://www.w3.org/TR/service-workers-1/"><cite>Service Workers 1</cite></a>. 19 November 2019. CR. URL: <a href="https://www.w3.org/TR/service-workers-1/">https://www.w3.org/TR/service-workers-1/</a>
1367+
</dl>
13621368
<h2 class="no-num no-ref heading settled" id="idl-index"><span class="content">IDL Index</span><a class="self-link" href="#idl-index"></a></h2>
13631369
<pre class="idl highlight def"><c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-registration-interface"><c- g>ServiceWorkerRegistration</c-></a> {
13641370
<c- b>readonly</c-> <c- b>attribute</c-> <a data-link-type="idl-name" href="#syncmanager"><c- n>SyncManager</c-></a> <a data-readonly data-type="SyncManager" href="#dom-serviceworkerregistration-sync"><code><c- g>sync</c-></code></a>;

tests/github/WICG/construct-stylesheets/index.html

+6
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,7 @@ <h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
21022102
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
21032103
<ol class="toc">
21042104
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
2105+
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
21052106
</ol>
21062107
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
21072108
</ol>
@@ -2827,6 +2828,11 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
28272828
<dt id="biblio-webidl">[WebIDL]
28282829
<dd>Boris Zbarsky. <a href="https://heycam.github.io/webidl/"><cite>Web IDL</cite></a>. 15 December 2016. ED. URL: <a href="https://heycam.github.io/webidl/">https://heycam.github.io/webidl/</a>
28292830
</dl>
2831+
<h3 class="no-num no-ref heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
2832+
<dl>
2833+
<dt id="biblio-css-cascade-5①">[CSS-CASCADE-5]
2834+
<dd>Elika Etemad; Miriam Suzanne; Tab Atkins Jr.. <a href="https://www.w3.org/TR/css-cascade-5/"><cite>CSS Cascading and Inheritance Level 5</cite></a>. 19 March 2021. WD. URL: <a href="https://www.w3.org/TR/css-cascade-5/">https://www.w3.org/TR/css-cascade-5/</a>
2835+
</dl>
28302836
<h2 class="no-num no-ref heading settled" id="idl-index"><span class="content">IDL Index</span><a class="self-link" href="#idl-index"></a></h2>
28312837
<pre class="idl highlight def"><c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://drafts.csswg.org/cssom-1/#cssstylesheet"><c- g>CSSStyleSheet</c-></a> {
28322838
<a class="idl-code" data-link-type="constructor" href="#dom-cssstylesheet-cssstylesheet"><c- g>constructor</c-></a>(<c- b>optional</c-> <a data-link-type="idl-name" href="#dictdef-cssstylesheetinit"><c- n>CSSStyleSheetInit</c-></a> <a href="#dom-cssstylesheet-cssstylesheet-options-options"><code><c- g>options</c-></code></a> = {});

0 commit comments

Comments
 (0)