@@ -171,6 +171,9 @@ function convert(infile, outfile) {
171171 }
172172 }
173173
174+ // Track used <dfn>s in order to identify the unused ones.
175+ const usedDfns = new Set ( ) ;
176+
174177 // Replace <span> with the inner <code> or a new <a>.
175178 // TODO: align more closely with Wattsi:
176179 // https://github.com/whatwg/wattsi/blob/b9c28036a2a174f7f87315164f001120596a95f1/src/wattsi.pas#L1454-L1487
@@ -262,6 +265,7 @@ function convert(infile, outfile) {
262265 span . replaceWith ( a ) ;
263266
264267 ensureLink ( a , dfn ) ;
268+ usedDfns . add ( dfn ) ;
265269 }
266270
267271 // Wrap <i data-x="..."> with <a>. Wattsi handling is here:
@@ -284,6 +288,7 @@ function convert(infile, outfile) {
284288 a . appendChild ( i ) ;
285289
286290 ensureLink ( a , dfn ) ;
291+ usedDfns . add ( dfn ) ;
287292 }
288293
289294 for ( const code of document . querySelectorAll ( 'pre > code' ) ) {
@@ -355,6 +360,7 @@ function convert(infile, outfile) {
355360 a . appendChild ( code ) ;
356361
357362 ensureLink ( a , dfn ) ;
363+ usedDfns . add ( dfn ) ;
358364 }
359365
360366 // Rewrite data-lt to lt.
@@ -372,6 +378,19 @@ function convert(infile, outfile) {
372378 elem . removeAttribute ( 'data-x-href' ) ;
373379 }
374380
381+ // Add noexport to unused <dfn>s to silence Bikeshed warnings about them.
382+ // TODO: vet for cases that are accidentally unused.
383+ for ( const dfn of crossRefs . values ( ) ) {
384+ if ( usedDfns . has ( dfn ) ) {
385+ continue ;
386+ }
387+ // This <dfn> is unused by Wattsi rules.
388+ if ( dfn . hasAttribute ( 'data-export' ) || dfn . hasAttribute ( 'export' ) ) {
389+ continue ;
390+ }
391+ dfn . setAttribute ( 'noexport' , '' ) ;
392+ }
393+
375394 // Simplify <a> to Bikeshed autolinks.
376395 for ( const a of document . querySelectorAll ( 'a' ) ) {
377396 break ;
0 commit comments