Skip to content

Commit bf8b407

Browse files
authored
[Extract elements] Strengthen logic for permission-elements (#2005)
Via w3c/browser-specs#2107 (comment) The `permission-elements` spec uses what looks like an element definition table to describe "common behaviours" of elements defined later in the spec. This needed to be added as an exception to the rule. The spec also links directly to the DOM interface. That simple case wasn't captured properly. The logic is now more sound in that it looks for an IDL interface `dfn` or a link to an IDL interface, and only parses the text to handle the HTML spec case where the link to the IDL interface is not qualified. Note: checked with a full crawl, this does not produce changes to the extracted elements so far, and allows to crawl `html-permissions` as well.
1 parent 8ca3a2d commit bf8b407

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

src/browserlib/extract-elements.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export default function (spec) {
3636
const dfns = [...heading.querySelectorAll('dfn')];
3737
if (dfns.length === 0) {
3838
// Ignore the definition of "Custom elements" in HTML
39-
if (getText(heading).match(/Core concepts/)) {
39+
// and the definition of "Common behaviours" in permission-elements
40+
if (getText(heading).match(/Core concepts/i) ||
41+
getText(heading).match(/Common behaviours/i)) {
4042
return null;
4143
}
4244
throw new Error('No dfn found in heading element: ' + heading.textContent);
@@ -101,14 +103,19 @@ export default function (spec) {
101103
dd = dd.nextElementSibling;
102104
}
103105
if (dd) {
104-
let match = dd.textContent.match(/^interface (.*?) /m);
105-
if (match) {
106-
res[prop] = match[1];
106+
const interfaceEl = dd.querySelector(`
107+
dfn[data-dfn-type=interface],
108+
a[data-link-type=idl]
109+
`);
110+
if (interfaceEl) {
111+
res[prop] = interfaceEl.textContent.trim();
107112
}
108113
else {
114+
// The HTML spec does not flag links to interfaces with a
115+
// data-link-type attribute.
109116
// NB: The sub/sup table uses a plural form for "Use", hence
110117
// the "?" for the final "s" in "Uses".
111-
match = dd.textContent.match(/^Uses? (.*?)[,\.\s]/);
118+
const match = dd.textContent.match(/^Uses? (.*?)[,\.\s]/);
112119
if (match) {
113120
res[prop] = match[1];
114121
}

test/extract-elements.js

Lines changed: 43 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)