Skip to content

Commit 47181d8

Browse files
fix(data-cite): remove premature heading API, cite sibling, and network-dependent logic
Agent-Logs-Url: https://github.com/speced/respec/sessions/68e1b631-cda5-40df-b376-0219553b29a6 Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
1 parent a15b7d4 commit 47181d8

2 files changed

Lines changed: 6 additions & 75 deletions

File tree

src/core/data-cite.js

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -185,59 +185,24 @@ export async function run() {
185185

186186
// Pre-compute cite details for each element (avoids double toCiteDetails calls)
187187
const citeDetailsMap = new Map();
188-
const headingQueries = [];
189188
for (const elem of elems) {
190-
const citeDetails = toCiteDetails(elem);
191-
citeDetailsMap.set(elem, citeDetails);
192-
// Collect elements that need heading text (triple-bracket cross-spec links)
193-
if (
194-
elem.localName === "a" &&
195-
elem.textContent === "" &&
196-
!elem.dataset.lt &&
197-
citeDetails.frag &&
198-
citeDetails.key !== THIS_SPEC
199-
) {
200-
const spec = citeDetails.key.replace(/^[!?]/, "").toLowerCase();
201-
const id = citeDetails.frag.replace("#", "");
202-
headingQueries.push({ spec, id });
203-
}
189+
citeDetailsMap.set(elem, toCiteDetails(elem));
204190
}
205191

206-
// Batch-fetch heading text from the headings API
207-
const headings = await fetchHeadings(headingQueries);
208-
209192
for (const elem of elems) {
210193
const originalKey = elem.dataset.cite;
211194
const citeDetails = citeDetailsMap.get(elem);
212195
const linkProps = await getLinkProps(citeDetails);
213196
if (linkProps) {
214-
// Use alias text (data-lt) if present and element is empty
215-
// (only applies to [[[...]]] triple-bracket expansions, not IDL references
216-
// which also use data-lt for lookup terms but have child content)
197+
// Use alias text (data-lt) if present and element is empty.
198+
// Only applies to [[[...]]] triple-bracket expansions (which set data-lt for
199+
// alias text). IDL references also use data-lt as a lookup term but already
200+
// have child content, so the textContent check prevents corrupting them.
217201
if (elem.dataset.lt && elem.textContent === "") {
218202
elem.textContent = elem.dataset.lt;
219203
delete elem.dataset.lt;
220204
}
221-
// Use heading text for cross-spec section links
222-
let headingSpecTitle = null;
223-
if (citeDetails.frag && elem.textContent === "") {
224-
const spec = citeDetails.key.replace(/^[!?]/, "").toLowerCase();
225-
const id = citeDetails.frag.replace("#", "");
226-
const heading = headings.get(`${spec}#${id}`);
227-
if (heading) {
228-
const secNum = heading.number ? `§\u00A0${heading.number} ` : "§ ";
229-
elem.textContent = `${secNum}${heading.title}`;
230-
headingSpecTitle = heading.specTitle;
231-
}
232-
}
233205
linkElem(elem, linkProps, citeDetails);
234-
// Add spec title cite element for heading links
235-
if (headingSpecTitle) {
236-
const cite = document.createElement("cite");
237-
cite.textContent = headingSpecTitle;
238-
elem.before(cite);
239-
cite.after(" ");
240-
}
241206
} else {
242207
const msg = `Couldn't find a match for "${originalKey}"`;
243208
if (elem.dataset.matchedText) {
@@ -250,40 +215,6 @@ export async function run() {
250215
sub("beforesave", cleanup);
251216
}
252217

253-
const HEADINGS_API_URL = "https://respec.org/xref/headings/";
254-
255-
/**
256-
* Fetches heading text from the headings API for cross-spec section links.
257-
* @param {{ spec: string; id: string }[]} queries
258-
* @returns {Promise<Map<string, { title: string; number?: string; specTitle: string }>>}
259-
*/
260-
async function fetchHeadings(queries) {
261-
const results = new Map();
262-
if (!queries.length) return results;
263-
264-
try {
265-
const response = await fetch(HEADINGS_API_URL, {
266-
method: "POST",
267-
body: JSON.stringify({ queries }),
268-
headers: { "Content-Type": "application/json" },
269-
});
270-
if (!response.ok) return results;
271-
const { result } = await response.json();
272-
for (const entry of result) {
273-
if (!entry.error) {
274-
results.set(`${entry.spec}#${entry.id}`, {
275-
title: entry.title,
276-
number: entry.number,
277-
specTitle: entry.specTitle,
278-
});
279-
}
280-
}
281-
} catch {
282-
// Headings API unavailable; fall back to spec title
283-
}
284-
return results;
285-
}
286-
287218
/**
288219
* Fetches and updates `biblio` with entries corresponding to the given elements.
289220
* @param {HTMLElement[]} elems - The elements requiring biblio entries.

tests/spec/core/inlines-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ describe("Core - Inlines", () => {
328328

329329
const noAliasAnchor = doc.querySelector("#no-alias a[href]");
330330
expect(noAliasAnchor).toBeTruthy();
331-
// Without headings API, falls back to spec title
331+
// spec title is used as link text when no alias is provided
332332
expect(noAliasAnchor.textContent).toBe("Fetch Standard");
333333
});
334334

0 commit comments

Comments
 (0)