Skip to content

Commit

Permalink
[IDL extraction] Ignore asides added by Bikeshed (#1463)
Browse files Browse the repository at this point in the history
Bikeshed may add definition panels next to the IDL code. These panels were not
properly ignored during the extraction, see for instance:
https://github.com/w3c/webref/blob/a9bd984c13414f17677dec8d06ba4028e4f74294/ed/idl/trusted-types.idl#L55

The update makes the code ignore asides. It also generalizes the code that was
dealing with such side info to exclude, and adds a few tests to check that
part.
  • Loading branch information
tidoust authored Jan 15, 2024
1 parent fbf33fc commit 40db906
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/browserlib/extract-webidl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@ function extractRespecIdl() {
.filter(el => !el.closest(informativeSelector))
.map(el => el.cloneNode(true))
.map(el => {
const header = el.querySelector('.idlHeader');
if (header) {
header.remove();
}
const tests = el.querySelector('details.respec-tests-details');
if (tests) {
tests.remove();
for (const ignore of el.querySelectorAll([
'aside', '.idlHeader', 'details.respec-tests-details',
].join(','))) {
ignore.remove();
}
return el;
})
Expand Down
30 changes: 30 additions & 0 deletions tests/extract-webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,36 @@ interface GreatIdl4 {}`
<h2 id="idl-index">IDL index</h2>index
<pre class="idl">interface GreatIdl {}</pre>`,
res: 'interface GreatIdl {}'
},

{
title: "ignores any embedded header",
html: `<h1 id=title>Title</h1>
<pre class="idl">
<div class="idlHeader">Look at this great IDL</div>
interface GreatIdl {}
<div class="idlHeader">There will be more</div>
</pre>`,
res: 'interface GreatIdl {}'
},

{
title: "ignores links to tests",
html: `<h1 id=title>Title</h1>
<pre class="idl">
interface <details class="respec-tests-details"><summary>3 tests</summary>See WPT</details>GreatIdl {}
interface <details class="respec-tests-details"><summary>2 tests</summary>See WPT</details>AnotherGreatIdl {}
</pre>`,
res: `interface GreatIdl {}
interface AnotherGreatIdl {}`
},

{
title: "ignores asides",
html: `<h1 id=title>Title</h1>
<pre class="idl">
interface GreatIdl<aside>The interface is referenced from...</aside> {}</pre>`,
res: 'interface GreatIdl {}'
}
];

Expand Down

0 comments on commit 40db906

Please sign in to comment.