Skip to content

Commit

Permalink
Dfns extraction: expand logic that skips imported definitions (#1789)
Browse files Browse the repository at this point in the history
The crawler expected "imported definitions" to use `<dfn>` as the wrapping
element with an inner `<a>` element. The Source map format spec used the
opposite pattern. This update expands the logic accordingly.

The Source map format spec actually swapped back the elements, but there
are a couple of other specs that use the same pattern (Audiobooks and the
JSON-LD API), and more specs may elect to do that in the future as well.

Close #1788.
  • Loading branch information
tidoust authored Mar 7, 2025
1 parent ca2b7f1 commit 35d1671
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/browserlib/extract-dfns.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,9 @@ export default function (spec, idToHeading = {}) {
// (pending a proper dfns curation process, see:
// https://github.com/w3c/webref/issues/789)
.filter(node => {
const link = node.querySelector('a[href^="http"]');
const link =
node.querySelector('a[href^="http"]') ??
node.closest('a[href^="http"]');
return !link ||
(node.textContent.trim() !== link.textContent.trim()) ||
(link.href === 'https://www.w3.org/TR/CSS2/syndata.html#vendor-keywords');
Expand Down
6 changes: 6 additions & 0 deletions tests/extract-dfns.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ const tests = [
changesToBaseDfn: [],
spec: "html"
},
{
title: "ignores definitions imported in the Source map format spec",
html: '<li>The <a href="https://infra.spec.whatwg.org/#byte-sequence"><dfn id="external-whatwg-infra-byte-sequence">byte sequence</dfn></a>',
changesToBaseDfn: [],
spec: "sourcemap"
},
{
"title": "extracts attribute definition from the SVG2 spec",
html: `<table class="attrdef def"><tr>
Expand Down

0 comments on commit 35d1671

Please sign in to comment.