Skip to content

Commit

Permalink
Prevent creating links from inline links inside links
Browse files Browse the repository at this point in the history
  • Loading branch information
dontcallmedom committed Sep 2, 2024
1 parent 91d975c commit 4ecde76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/inlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ 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;
}

Expand Down
6 changes: 5 additions & 1 deletion tests/spec/core/inlines-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<section>
<dfn id="dfn">
Expand All @@ -639,14 +639,18 @@ describe("Core - Inlines", () => {
{{ ReferrerPolicy/"no-referrer" }}
123
</dfn>
<a id="link" href="#dfn">A link containing an IDL reference {{Window}}</a>
</section>
`;
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)");
Expand Down

0 comments on commit 4ecde76

Please sign in to comment.