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

Commit

Permalink
fix(core/inlines): link global element attributes (speced#3657)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored Jun 28, 2021
1 parent 06eeced commit e6b8b50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/core/inlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ const inlineElement = /(?:\[\^[^^]+\^\])/; // Inline [^element^]
*/
function inlineElementMatches(matched) {
const value = matched.slice(2, -2).trim();
const [element, attribute, attrValue] = value
const [forPart, attribute, attrValue] = value
.split("/", 3)
.map(s => s && s.trim())
.filter(s => !!s);

const [xrefType, xrefFor, textContent] = (() => {
if (attrValue) {
return ["attr-value", `${element}/${attribute}`, attrValue];
// [^ /role ^], for example
const isGlobalAttr = value.startsWith("/");
if (isGlobalAttr) {
return ["element-attr", null, forPart];
} else if (attrValue) {
return ["attr-value", `${forPart}/${attribute}`, attrValue];
} else if (attribute) {
return ["element-attr", element, attribute];
return ["element-attr", forPart, attribute];
} else {
return ["element", null, element];
return ["element", null, forPart];
}
})();
return html`<code
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 @@ -366,12 +366,13 @@ describe("Core - Inlines", () => {
);
});

it("processes inline inline [^element^]s.", async () => {
it("processes inline [^element^] and hierarchies.", async () => {
const body = `
<section>
<p id="test">[^body^]</p>
<p id="test2">[^iframe/allow^]</p>
<p id="test3">[^ html-global/inputmode/text ^]</p>
<p id="test4">[^ /role ^]</p>
</section>
`;
const doc = await makeRSDoc(makeStandardOps({ xref: ["HTML"] }, body));
Expand All @@ -383,6 +384,9 @@ describe("Core - Inlines", () => {
const inputModeAnchor = doc.querySelector("#test3 a");
expect(inputModeAnchor.textContent).toBe("text");
expect(inputModeAnchor.hash).toBe("#attr-inputmode-keyword-text");
const roleAttribute = doc.querySelector("#test4 a");
expect(roleAttribute.textContent).toBe("role");
expect(roleAttribute.hash).toBe("#attr-aria-role");
});

it("processes [= BikeShed style inline links =]", async () => {
Expand Down

0 comments on commit e6b8b50

Please sign in to comment.