Skip to content

Commit

Permalink
Links extraction: skip dfn panels (#1653)
Browse files Browse the repository at this point in the history
Via #1584 (comment).

Aside dfn panels only contain links that already appear somewhere else in the
spec.

These links were extracted and categorized as `autolinks` when they appeared in
the final index of a Bikeshed spec, which essentially did not do anything
because the links had already been extracted as `autolinks` in any case.

The problem is that Respec also uses similar panels (but no `<aside>`), and
Bikeshed sometimes outputs the panels at the end of the document, and not
within the index itself as expected in the code. In these situations, the
links were extracted a second time, as `rawlinks`. Not extracting the panels
avoids duplication entirely.
  • Loading branch information
tidoust authored Aug 22, 2024
1 parent ca6bd83 commit 4466dda
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/browserlib/extract-links.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ export default function () {
// self, the GitHub repo, the implementation report, and other
// documents that don't need to appear in the list of references.
// Also ignore links in <del> elements that appear when specs
// carry their diff (e.g. W3C Recs with candidate corrections)
if (n.closest('.head, del')) return;
// carry their diff (e.g. W3C Recs with candidate corrections).
// And then ignore links in aside dfn panels. They only contain internal
// links or links that already appear elsewhere in the spec.
if (n.closest('.head, del, .dfn-panel')) return;
const pageUrl = n.href.split('#')[0];
// links generated by authoring tools have data-link-type or data-xref-type set
// Bikeshed also adds automatic untyped links in the generatedindex ("ul.index aside")
let linkSet = n.dataset.linkType || n.dataset.xrefType || n.closest("ul.index aside") ? autolinks : rawlinks;
let linkSet = n.dataset.linkType || n.dataset.xrefType ? autolinks : rawlinks;
if (!linkSet[pageUrl]) {
linkSet[pageUrl] = {anchors: new Set()};
}
Expand Down
19 changes: 16 additions & 3 deletions tests/extract-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ const testLinks = [
title: "extracts links with fragments",
html: `<h1 id=title>Title</h1>
<p><a href="https://dom.spec.whatwg.org/#ranges">DOM Standard</a></p>
<p><a href="https://dom.spec.whatwg.org/#nodes" data-xref-type="dfn">DOM Standard</a></p><ul class="index"><li><aside><a href="https://dom.spec.whatwg.org/#element">Element</a></aside></li></ul>`,
<p><a href="https://dom.spec.whatwg.org/#nodes" data-xref-type="dfn">DOM Standard</a></p>`,
res: {
autolinks: {
"https://dom.spec.whatwg.org/": {
"anchors": [
"nodes",
"element"
"nodes"
]
}
},
Expand All @@ -63,6 +62,20 @@ const testLinks = [
}
}
},

{
title: "does not extract links in aside dfns panels",
html: `<h1 id=title>Title</h1>
<ul class="index"><li><aside class="dfn-panel"> <a href="https://dom.spec.whatwg.org/#element">Element</a></aside></li></ul>
<aside class="dfn-panel"><a href="https://dom.spec.whatwg.org/#nodes">Nodes</a></aside>
<div class="dfn-panel" role="dialog" hidden=""><div>
<a href="https://dom.spec.whatwg.org/#ranges">Permalink</a>
</div></div>`,
res: {
autolinks: {},
rawlinks: {}
}
},
];

describe("Links extraction", function () {
Expand Down

0 comments on commit 4466dda

Please sign in to comment.