Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links extraction: skip dfn panels #1653

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading