Skip to content

Commit 8a35909

Browse files
committed
feat(core/dfn-index): support data-noindex to exclude from external terms index
Closes #4895
1 parent e243de4 commit 8a35909

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎src/core/dfn-index.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ const localizationStrings = {
4646
dfnOf: "definición de",
4747
definesFollowing: "define lo siguiente:",
4848
},
49+
fr: {
50+
heading: "Index",
51+
headingExternal: "Termes définis par référence",
52+
headingLocal: "Termes définis par cette spécification",
53+
dfnOf: "définition de",
54+
definesFollowing: "définit les termes suivants :",
55+
},
4956
ja: {
5057
heading: "索引",
5158
headingExternal: "参照によって定義された用語",
@@ -340,6 +347,9 @@ function collectExternalTerms() {
340347
if (!elem.dataset.cite) {
341348
continue;
342349
}
350+
if ("noindex" in elem.dataset) {
351+
continue;
352+
}
343353
const { cite, citeFrag, xrefType, linkType, matchedText } = elem.dataset;
344354
// [[[SPEC#id]]] section links have both citeFrag and matchedText; skip them.
345355
if (citeFrag && matchedText) {
@@ -458,4 +468,8 @@ function cleanup(doc) {
458468
doc
459469
.querySelectorAll("#index-defined-here li[data-id]")
460470
.forEach(el => el.removeAttribute("data-id"));
471+
472+
doc
473+
.querySelectorAll("a[data-noindex]")
474+
.forEach(el => el.removeAttribute("data-noindex"));
461475
}

‎tests/spec/core/dfn-index-spec.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,21 @@ describe("Core — dfn-index", () => {
502502
expect(parsing1.id).toBe("index-term-parsing");
503503
expect(parsing2.id).toBe("index-term-parsing-0");
504504
});
505+
506+
it("excludes terms with data-noindex from the external index", async () => {
507+
const body = `<section data-cite="DOM">
508+
<h2>TEST</h2>
509+
<p>{{ Event }} {{ Event/type }}</p>
510+
<p><a data-cite="DOM#interface-event" data-noindex>Event (noindex)</a></p>
511+
</section>
512+
<section id="index"></section>`;
513+
const ops = makeStandardOps({ xref: "web-platform" }, body);
514+
const doc = await makeRSDoc(ops);
515+
const externalIndex = doc.getElementById("index-defined-elsewhere");
516+
const terms = [...externalIndex.querySelectorAll(".index-term")].map(el =>
517+
el.textContent.trim()
518+
);
519+
expect(terms).not.toContain("Event (noindex)");
520+
});
505521
});
506522
});

0 commit comments

Comments
 (0)