From a9285fa600dc15f544206945808b25dd974da6b9 Mon Sep 17 00:00:00 2001 From: Dominique Hazael-Massieux Date: Mon, 2 Sep 2024 14:40:36 +0200 Subject: [PATCH 1/3] Prevent creating links from inline links inside links --- src/core/inlines.js | 5 +++-- tests/spec/core/inlines-spec.js | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/inlines.js b/src/core/inlines.js index 71f8308b98..bba816a3d1 100644 --- a/src/core/inlines.js +++ b/src/core/inlines.js @@ -145,9 +145,10 @@ function inlineXrefMatches(matched, text) { } const node = idlStringToHtml(ref); - // If it's inside a dfn, it should just be coded, not linked. + // If it's inside a dfn or a `a`, it should just be coded, not linked. // This is because dfn elements are treated as links by ReSpec via role=link. - const renderAsCode = !!text.parentElement.closest("dfn"); + const renderAsCode = + !!text.parentElement.closest("dfn") || !!text.parentElement.closest("a"); return renderAsCode ? inlineCodeMatches(`\`${node.textContent}\``) : node; } diff --git a/tests/spec/core/inlines-spec.js b/tests/spec/core/inlines-spec.js index 7e26c43818..a08815174c 100644 --- a/tests/spec/core/inlines-spec.js +++ b/tests/spec/core/inlines-spec.js @@ -629,7 +629,7 @@ describe("Core - Inlines", () => { expect(primitiveData.lt).toBe("unsigned short"); }); - it("doesn't link processed inline WebIDL if inside a definition", async () => { + it("doesn't link processed inline WebIDL if inside a definition or a link", async () => { const body = `
@@ -639,14 +639,18 @@ describe("Core - Inlines", () => { {{ ReferrerPolicy/"no-referrer" }} 123 + A link containing an IDL reference {{Window}}
`; const doc = await makeRSDoc(makeStandardOps(null, body)); const dfn = doc.getElementById("dfn"); expect(dfn.querySelector("a")).toBeNull(); + const link = doc.getElementById("link"); + expect(link.querySelector("a")).toBeNull(); const codeElements = dfn.querySelectorAll("code"); expect(codeElements).toHaveSize(3); + expect(link.querySelectorAll("code")).toHaveSize(1); const [eventListen, event, noRef] = codeElements; expect(eventListen.textContent).toBe("addEventListener(type, callback)"); From 197d6680f7dca71364eeaa410f0e6ecdd4ffda5a Mon Sep 17 00:00:00 2001 From: Dominique Hazael-Massieux Date: Thu, 5 Sep 2024 13:52:38 +0200 Subject: [PATCH 2/3] Simplify detection of ancestor with a single selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit per review suggestion Co-authored-by: François Daoust --- src/core/inlines.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/inlines.js b/src/core/inlines.js index bba816a3d1..8741896536 100644 --- a/src/core/inlines.js +++ b/src/core/inlines.js @@ -148,7 +148,7 @@ function inlineXrefMatches(matched, text) { // If it's inside a dfn or a `a`, it should just be coded, not linked. // This is because dfn elements are treated as links by ReSpec via role=link. const renderAsCode = - !!text.parentElement.closest("dfn") || !!text.parentElement.closest("a"); + !!text.parentElement.closest("dfn,a"); return renderAsCode ? inlineCodeMatches(`\`${node.textContent}\``) : node; } From 8e0864ca6fe0a24dc959d03e709c312f8a306de4 Mon Sep 17 00:00:00 2001 From: Dominique Hazael-Massieux Date: Thu, 5 Sep 2024 13:55:04 +0200 Subject: [PATCH 3/3] Fix lint --- src/core/inlines.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/inlines.js b/src/core/inlines.js index 8741896536..b6651e2b86 100644 --- a/src/core/inlines.js +++ b/src/core/inlines.js @@ -147,8 +147,7 @@ function inlineXrefMatches(matched, text) { const node = idlStringToHtml(ref); // If it's inside a dfn or a `a`, it should just be coded, not linked. // This is because dfn elements are treated as links by ReSpec via role=link. - const renderAsCode = - !!text.parentElement.closest("dfn,a"); + const renderAsCode = !!text.parentElement.closest("dfn,a"); return renderAsCode ? inlineCodeMatches(`\`${node.textContent}\``) : node; }