Skip to content

feat(css-syntax): accept an optional CSS reference resolver - #875

Open
caugner wants to merge 2 commits into
mainfrom
csssyntax-optional-ref-resolver
Open

feat(css-syntax): accept an optional CSS reference resolver#875
caugner wants to merge 2 commits into
mainfrom
csssyntax-optional-ref-resolver

Conversation

@caugner

@caugner caugner commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Description

Add an optional CssRefResolver callback to render_formal_syntax, letting the caller decide where a <type> or <'property'> node links, or that it shouldn't link at all.

  • CssRefKind tells the resolver whether the node is a type or a property.
  • A new SyntaxRenderer::render_reference helper replaces the two hand-rolled format! link builders in render_node.
  • Passing resolver: None keeps the previous behavior, so this is a no-op on its own.

Motivation

render_node hardcoded Reference/Values/{slug} and Reference/Properties/{slug} for every node. css-syntax has no access to the MDN page tree, so it cannot tell whether those pages exist, and the webref grammars reference many spec-internal productions that MDN does not document. Injecting a resolver lets rari-doc supply that knowledge without inverting the crate dependency.

Passing the node kind rather than just the slug means the resolver never has to re-derive the category from a URL or a naming convention.

Additional details

Split out of #874 to keep the plumbing separate from the behavior change. All 20 existing css-syntax tests pass with unchanged expected HTML, which is what verifies the None path is a no-op; two new tests cover the Some(resolver) path for both node kinds.

Related issues and pull requests

Relates to #874, which uses this to fix 1857 broken formal-syntax links.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

a1e20f7 was deployed to: https://rari-pr875.review.mdn.allizom.net/

@caugner
caugner marked this pull request as ready for review September 4, 2026 09:23
@caugner
caugner requested a review from a team as a code owner September 4, 2026 09:23
@caugner
caugner requested a review from LeoMcA September 4, 2026 09:23
@caugner
caugner force-pushed the csssyntax-optional-ref-resolver branch from b10f195 to 32127f0 Compare September 4, 2026 09:52
Comment thread crates/css-syntax/src/syntax.rs Outdated
Comment thread crates/css-syntax/src/syntax.rs Outdated
@caugner
caugner marked this pull request as draft September 4, 2026 13:35
@caugner
caugner marked this pull request as ready for review September 4, 2026 13:40
caugner and others added 2 commits September 4, 2026 16:05
`SyntaxRenderer::render_node` built `<type>` and `<'property'>` links by
hand, hardcoding `Reference/Values/{slug}` and `Reference/Properties/{slug}`.
`css-syntax` has no access to the MDN page tree, so it cannot tell whether
those pages exist.

Add a `CssRefResolver` callback, threaded from `render_formal_syntax` to a
new `SyntaxRenderer::render_reference` helper, which the caller can use to
map a reference to the sub-path documenting it, or to `None` to render the
node unlinked. `CssRefKind` tells the resolver whether the node is a type or
a property, sparing it from having to re-derive that from the slug.

Passing `None` keeps the previous link-everything behavior, so this commit is
a no-op on its own.
Co-authored-by: Leo McArdle <leo@mca.is>
Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants