Skip to content

Commit ca4f622

Browse files
committed
feat(inlines): support [[[SPEC#id]]] for cross-spec section links
Extends the inline expansion regex to allow [[[SPEC#fragment-id]]], e.g. [[[fetch#data-fetch]]]. The result is a link to that spec's specific section (href resolved via the existing data-cite machinery), with the spec title as the link text. Existing [[[SPEC]]] and [[[#local-id]]] syntax is unchanged.
1 parent 7229741 commit ca4f622

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/core/inlines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const inlineCodeRegExp = /(?:`[^`]+`)(?!`)/; // `code`
6767
const inlineIdlReference = /(?:{{[^}]+\?*}})/; // {{ WebIDLThing }}, {{ WebIDLThing? }}
6868
const inlineVariable = /\B\|\w[\w\s]*(?:\s*:[\w\s&;"?<>]+\??)?\|\B/; // |var : Type?|
6969
const inlineCitation = /(?:\[\[(?:!|\\|\?)?[\w.-]+(?:|[^\]]+)?\]\])/; // [[citation]]
70-
const inlineExpansion = /(?:\[\[\[(?:!|\\|\?)?#?[\w-.]+\]\]\])/; // [[[expand]]]
70+
const inlineExpansion = /(?:\[\[\[(?:!|\\|\?)?#?[\w-.]+(?:#[\w-.]+)?\]\]\])/; // [[[expand]]] or [[[SPEC#id]]]
7171
const inlineAnchor = /(?:\[=[^=]+=\])/; // Inline [= For/link =]
7272
const inlineElement = /(?:\[\^[^^]+\^\])/; // Inline [^element^]
7373

tests/spec/core/inlines-spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,27 @@ describe("Core - Inlines", () => {
284284
expect(notFound.textContent).toBe("[[[not-found]]]");
285285
});
286286

287+
it("links to specific section of another spec using [[[SPEC#id]]] syntax", async () => {
288+
const config = {
289+
localBiblio: {
290+
fetch: {
291+
title: "Fetch Standard",
292+
href: "https://fetch.spec.whatwg.org/",
293+
},
294+
},
295+
};
296+
const body = `
297+
<section id="test">
298+
<p id="output">[[[fetch#data-fetch]]]</p>
299+
</section>
300+
`;
301+
const doc = await makeRSDoc(makeStandardOps(config, body));
302+
const anchor = doc.querySelector("#output a[href]");
303+
expect(anchor).toBeTruthy();
304+
expect(anchor.href).toBe("https://fetch.spec.whatwg.org/#data-fetch");
305+
expect(anchor.textContent).toBe("Fetch Standard");
306+
});
307+
287308
it("allows [[[#...]]] to be a general expander for ids in document", async () => {
288309
/** @param {string} text */
289310
function generateDataIncludeUrl(text) {

0 commit comments

Comments
 (0)