Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,18 @@ export function getDfnTitles(elem) {
titleSet.add(normText);
titleSet.delete("");

// For enum-value dfns, authors often write <dfn>"value"</dfn> with surrounding
// quotes (mirroring WebIDL syntax). Register the unquoted form as well so that
// WebIDL lookups and {{ EnumType/"value" }} inline refs can find the dfn.
if (
elem.dataset.dfnType === "enum-value" &&
normText.startsWith('"') &&
normText.endsWith('"') &&
normText.length > 2
) {
titleSet.add(normText.slice(1, -1));
}

// We could have done this with @data-lt (as the logic is same), but if
// @data-lt was not present, we would end up using @data-local-lt as element's
// id (in other words, we prefer textContent over @data-local-lt for dfn id)
Expand Down
57 changes: 57 additions & 0 deletions tests/spec/core/webidl-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,63 @@ enum EnumBasic {
);
expect(doc.getElementById("idl-def-enumbasic")).toBeTruthy();
});

it("links quoted enum value definitions to IDL", async () => {
// Authors sometimes write <dfn>"value"</dfn> with surrounding quotes to
// mirror WebIDL syntax. ReSpec must still match these dfns to the IDL
// enum member (which webidl2 reports without quotes).
const body = `
<pre class="idl">
enum QuotedEnum {
"alpha",
"beta with spaces"
};
</pre>
<p>
<dfn data-dfn-for="QuotedEnum" data-dfn-type="enum-value">"alpha"</dfn>
<dfn data-dfn-for="QuotedEnum" data-dfn-type="enum-value">"beta with spaces"</dfn>
</p>
<p id="link-test" data-link-for="QuotedEnum">
<a>alpha</a> — <a>beta with spaces</a>
</p>
`;
const ops = makeStandardOps(null, body);
const doc = await makeRSDoc(ops);

// The IDL should link to the user-provided dfns (no extra auto-generated dfns).
const alphaDfn = doc.getElementById("dom-quotedenum-alpha");
expect(alphaDfn).withContext("dfn for alpha must exist").toBeTruthy();
expect(alphaDfn.dataset.dfnType)
.withContext("dfn type must be enum-value")
.toBe("enum-value");

const betaDfn = doc.getElementById("dom-quotedenum-beta-with-spaces");
expect(betaDfn)
.withContext("dfn for beta with spaces must exist")
.toBeTruthy();

// The IDL block must link to the user-provided dfns.
const idlBlock = doc.querySelector("pre.idl code");
expect(idlBlock.querySelector("a[href='#dom-quotedenum-alpha']"))
.withContext("IDL block links alpha to user dfn")
.toBeTruthy();
expect(
idlBlock.querySelector("a[href='#dom-quotedenum-beta-with-spaces']")
)
.withContext("IDL block links beta-with-spaces to user dfn")
.toBeTruthy();

// Inline links should resolve too.
const linkTest = doc.getElementById("link-test");
expect(linkTest.querySelector("a[href='#dom-quotedenum-alpha']"))
.withContext("inline link to alpha resolves")
.toBeTruthy();
expect(
linkTest.querySelector("a[href='#dom-quotedenum-beta-with-spaces']")
)
.withContext("inline link to beta with spaces resolves")
.toBeTruthy();
});
});

it("should handle enumeration value definitions", () => {
Expand Down
Loading