Skip to content

Commit

Permalink
Generate an ID for autolinks without a fragment. Properly dedup autog…
Browse files Browse the repository at this point in the history
…enned IDs, too. Fixes #2531
  • Loading branch information
tabatkins committed Apr 28, 2023
1 parent dade1fe commit 33416a8
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 116 deletions.
6 changes: 4 additions & 2 deletions bikeshed/dfnpanels/dfnpanels.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ def addExternalDfnPanel(termEl: t.ElementT, ref: t.RefWrapper, doc: t.SpecT) ->
return
termText = h.textContent(termEl)
sectionsJson = []
counter = 0
for text, els in refsFromSection.items():
refsJson = []
for i, el in enumerate(els):
for el in els:
linkID = el.get("id")
if linkID is None:
linkID = h.uniqueID("external-link", ref.url, termID) + str(i)
linkID = h.uniqueID("external-link", ref.url, termID) + str(counter)
counter += 1
el.set("id", h.safeID(doc, linkID))
refsJson.append(
{
Expand Down
4 changes: 3 additions & 1 deletion bikeshed/unsortedJunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,9 @@ def decorateAutolink(doc: t.SpecT, el: t.ElementT, linkType: str, linkText: str,
unused1, unused2, id = ref.url.partition("#") # pylint: disable=unused-variable
if id:
el.set("id", f"ref-for-{id}")
el.set("data-silently-dedup", "")
else:
el.set("id", "ref-for-something")
el.set("data-silently-dedup", "")

# Get all the values that the type expands to, add it as a title.
if linkType == "type":
Expand Down
14 changes: 7 additions & 7 deletions tests/github/WICG/responsive-image-client-hints/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/github/WICG/sanitizer-api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ <h3 class="heading settled" data-level="3.4" id="mutated-xss"><span class="secno
avoided.</p>
<h2 class="heading settled" data-level="4" id="ack"><span class="secno">4. </span><span class="content">Acknowledgements</span><a class="self-link" href="#ack"></a></h2>
<p>Cure53’s <a data-link-type="biblio" href="#biblio-dompurify" title="DOMPurify">[DOMPURIFY]</a> is a clear inspiration for the API this document
describes, as is Internet Explorer’s <code class="idl"><a data-link-type="idl" href="https://msdn.microsoft.com/en-us/library/cc848922(v=vs.85).aspx" id="24ae72850">window.toStaticHTML()</a></code>.</p>
describes, as is Internet Explorer’s <code class="idl"><a data-link-type="idl" href="https://msdn.microsoft.com/en-us/library/cc848922(v=vs.85).aspx" id="ref-for-something">window.toStaticHTML()</a></code>.</p>
<h2 class="heading settled" id="constants"><span class="content">Appendix A: Built-in Constants</span><a class="self-link" href="#constants"></a></h2>
<p><em>This appendix is normative.</em></p>
<p>These constants define core behaviour of the Sanitizer algorithm.</p>
Expand Down Expand Up @@ -1565,7 +1565,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
window.dfnpanelData['2823e871'] = {"dfnID": "2823e871", "url": "https://dom.spec.whatwg.org/#interface-Document", "dfnText": "Document", "refSections": [{"refs": [{"id": "ref-for-interface-Document"}], "title": "2.2. Input Types"}, {"refs": [{"id": "ref-for-interface-Document\u2460"}], "title": "2.4. Algorithms"}], "external": true};
window.dfnpanelData['49a2843d'] = {"dfnID": "49a2843d", "url": "https://dom.spec.whatwg.org/#documentfragment", "dfnText": "DocumentFragment", "refSections": [{"refs": [{"id": "ref-for-documentfragment"}], "title": "2.1. Sanitizer API"}, {"refs": [{"id": "ref-for-documentfragment\u2460"}, {"id": "ref-for-documentfragment\u2461"}], "title": "2.2. Input Types"}, {"refs": [{"id": "ref-for-documentfragment\u2462"}], "title": "2.4. Algorithms"}], "external": true};
window.dfnpanelData['44d397b3'] = {"dfnID": "44d397b3", "url": "https://dom.spec.whatwg.org/#dom-document-createdocumentfragment", "dfnText": "createDocumentFragment", "refSections": [{"refs": [{"id": "ref-for-dom-document-createdocumentfragment"}], "title": "2.4. Algorithms"}], "external": true};
window.dfnpanelData['d354f084'] = {"dfnID": "d354f084", "url": "https://msdn.microsoft.com/en-us/library/cc848922(v=vs.85).aspx", "dfnText": "window.toStaticHTML()", "refSections": [{"refs": [{"id": "24ae72850"}], "title": "4. Acknowledgements"}], "external": true};
window.dfnpanelData['d354f084'] = {"dfnID": "d354f084", "url": "https://msdn.microsoft.com/en-us/library/cc848922(v=vs.85).aspx", "dfnText": "window.toStaticHTML()", "refSections": [{"refs": [{"id": "ref-for-something"}], "title": "4. Acknowledgements"}], "external": true};
window.dfnpanelData['296f3551'] = {"dfnID": "296f3551", "url": "https://dom.spec.whatwg.org/#element", "dfnText": "Element", "refSections": [{"refs": [{"id": "ref-for-element"}], "title": "1. Introduction"}], "external": true};
window.dfnpanelData['543878fa'] = {"dfnID": "543878fa", "url": "https://dom.spec.whatwg.org/#concept-node-append", "dfnText": "append", "refSections": [{"refs": [{"id": "ref-for-concept-node-append"}], "title": "2.4. Algorithms"}], "external": true};
window.dfnpanelData['77211728'] = {"dfnID": "77211728", "url": "https://dom.spec.whatwg.org/#concept-element-attribute", "dfnText": "attribute list", "refSections": [{"refs": [{"id": "ref-for-concept-element-attribute"}], "title": "2.4. Algorithms"}], "external": true};
Expand Down
Loading

0 comments on commit 33416a8

Please sign in to comment.