feat(core/inlines): support [[[SPEC#id]]] for cross-spec section links#5146
feat(core/inlines): support [[[SPEC#id]]] for cross-spec section links#5146marcoscaceres wants to merge 32 commits intomainfrom
Conversation
02aca58 to
ca4f622
Compare
There was a problem hiding this comment.
Pull request overview
Extends ReSpec’s [[[...]]] inline expansion parsing so authors can cite a spec and link directly to a section using a fragment (e.g., [[[fetch#data-fetch]]]), leveraging existing data-cite fragment handling.
Changes:
- Updated the
[[[...]]]inline-expansion regex to allow an optional#fragmentsuffix. - Added a unit test asserting that
[[[fetch#data-fetch]]]resolves to the spec URL with the fragment and uses the spec title as link text.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/core/inlines.js |
Broadens inlineExpansion matching to include SPEC#fragment forms. |
tests/spec/core/inlines-spec.js |
Adds coverage for cross-spec section linking via [[[SPEC#id]]]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@sidvishnoi Good point. The spec title alone isn't useful for section-level links. The intended behavior for The data for this is available in w3c/webref's headings data. I've opened speced/respec-web-services#469 to add a Holding this PR until the headings API is available and the inlines.js expansion can use real heading text. Will also add alias support ( |
2de2f1e to
da52313
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot Can you check and fix any issues identified by ci? |
Head branch was pushed to by a user without write access
Fixed in 8c873cf. The CI failures were caused by my The fix: guard with |
|
@copilot, can you fix any outstanding comments and resolve any that have already been addressed? |
Done in 47181d8. Here's the status of each outstanding thread:
|
47181d8 to
28a2960
Compare
toCiteDetails() may mutate elem.dataset.cite for elements with fragment-only citations (#foo). Capture the original key before pre-computation so error messages show what the author wrote.
…atterns Agent-Logs-Url: https://github.com/speced/respec/sessions/b4127b19-353e-4a16-a5e8-60b46aa9ae47 Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
The data-lt expansion for [[[SPEC#id]]] alias text must not overwrite textContent when data-lt is "the-empty-string" (the WebIDL sentinel for enum value ""). Matches the existing guard in linkElem.
- Test [[[!SPEC#id]]] normative with fragment - Test [[[?SPEC#id]]] informative with fragment - Test [[[?SPEC#id|alias]]] informative + fragment + alias - Test [[[?SPEC|alias]]] informative + alias, no fragment - Test [[[not-found|Custom Text]]] error path with alias - Fix misleading "avoids double calls" comment in data-cite.js
…s and error paths
Agent-Logs-Url: https://github.com/speced/respec/sessions/5255d49c-dcf0-4e89-8358-5afc6cefefce Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Per Sid's review: moved the complex expansion syntax validation from the regex into the handler function. The regex now matches any [[[...]]] content. Invalid syntax gets a warning with expected formats.
Rename generic 'defined' constant to 'inlineExpansionPattern'. Update regex comment to list all supported syntaxes. Remove stray JSDoc block that didn't document any function.
- inlineRefMatches return type: HTMLElement | string (returns string on invalid syntax) - Expand warning hint to include all supported forms (aliases, prefixes) - Fix stale data-cite.js comment about toCiteDetails mutation ordering
Strip !/?/\ prefix before checking if ref starts with # so that [[[!#id]]] and [[[?#id]]] are treated as in-document links (href) rather than cross-spec citations (data-cite). Previously the prefix caused the # check to fail, routing them to the wrong code path.
…e for heading (#5207) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…sification Agent-Logs-Url: https://github.com/speced/respec/sessions/357f987f-64f6-4773-9ca0-76c94ec3abaa Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
b98c3bc to
ced1700
Compare
Calls POST /xref/search/headings to fetch actual section heading text for [[[SPEC#id]]] cross-spec links. When the API returns a result, the link text shows "§N Title" (e.g., "§4 Fetching") instead of just the spec title. Falls back to spec title when the API is unavailable or has no data for the given fragment. Alias text ([[[SPEC#id|text]]]) always takes precedence over heading titles.
- Merge heading collection into existing citeDetailsMap loop - Default `result` destructuring to empty array for defensive parsing - Guard against empty heading titles producing invisible links - Use regex in heading test for section number flexibility
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove API_URL import from xref.js to avoid its top-level side effects (preconnect link injection). Define HEADINGS_API_URL locally. - Widen heading test assertion to accept unnumbered headings (bare title without section number prefix).
[[[\SPEC#id]]] now renders as literal [[[SPEC#id]]] text, matching
the escape pattern used by [[\internal-slot]] and {{\EscapedIDL}}.
Summary
[[[...]]]inline expansion syntax to allow[[[SPEC#fragment]]]#fragmentappended[[[fetch#data-fetch]]]→ link to the Fetch spec's#data-fetchsection, with link text taken from the spec titleTest plan
pnpm test:unit[[[fetch#data-fetch]]]produces a link tohttps://fetch.spec.whatwg.org/#data-fetch