Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
feat(core/link-to-dfn): support abstract-op dfn linking (speced#4439)
Browse files Browse the repository at this point in the history
  • Loading branch information
dontcallmedom authored Apr 27, 2023
1 parent 4bceb17 commit 20e478b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/inlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function inlineAnchorMatches(matched) {
const processedContent = processInlineContent(text);
const forContext = isFor ? norm(isFor) : null;
return html`<a
data-link-type="dfn"
data-link-type="dfn|abstract-op"
data-link-for="${forContext}"
data-xref-for="${forContext}"
data-lt="${linkingText}"
Expand Down
7 changes: 6 additions & 1 deletion src/core/link-to-dfn.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ function findMatchingDfn(anchor, titleToDfns) {
const dfnsByType = titleToDfns.get(target.title).get(target.for);
const { linkType } = anchor.dataset;
if (linkType) {
return dfnsByType.get(linkType) || dfnsByType.get("dfn");
for (const type of linkType.split("|")) {
if (dfnsByType.get(type)) {
return dfnsByType.get(type);
}
}
return dfnsByType.get("dfn");
} else {
// Assumption: if it's for something, it's more likely IDL.
const type = target.for ? "idl" : "dfn";
Expand Down
18 changes: 18 additions & 0 deletions tests/spec/core/link-to-dfn-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ describe("Core — Link to definitions", () => {
expect([...idlLinks].map(a => a.hash)).toEqual(Array(2).fill("#idl-card"));
});

it("recognizes inline links to abstract-op definitions", async () => {
const body = `
<section>
theeee <dfn id="dfn-algo" class="abstract-op">make-me-a-sandwich algorithm</dfn> is an algorithm.
<div id="dfn-links">
When hungry, use the [= make-me-a-sandwich algorithm =]; the <a data-link-type="abstract-op">make-me-a-sandwich algorithm</a> is less useful when thirsty
</div>
</section>
`;
const ops = makeStandardOps(null, body);
const doc = await makeRSDoc(ops);

const conceptLinks = doc.querySelectorAll("#dfn-links a");
expect([...conceptLinks].map(a => a.hash)).toEqual(
Array(2).fill("#dfn-algo")
);
});

it("treats internal slots as idl", async () => {
const body = `
<section id="test">
Expand Down

0 comments on commit 20e478b

Please sign in to comment.