Skip to content

Conversation

@argl
Copy link
Contributor

@argl argl commented Sep 18, 2025

Description

This implements the usage of data from webref-css version 7.x. That version only provides a consolidated version of the data, so we can get rid of the brittle logic around selecting a CSS level we show. The editorial responsibility therefore lies with the maintainers of webref-css.

This is the basis of our CSS formal syntax rendering.

Motivation

Upstream major version change.

Additional details

Webref-css changelog
Diff of the document changes induced by this PR: 255 changes

<color> example formal syntax

Before
image

After
image

There are numerous additions to this in the v7 data, namely the correct introduction of light-dark() (which we document on the page) and device-cmyk() (which is not implemented by any browser by time of writing).

Since the specification titles are no more included with the webref data, titles are pulled in from the browser-specs data package.

Related issues and pull requests

Fixes #304

@argl
Copy link
Contributor Author

argl commented Sep 22, 2025

Waiting for a decision from content for the copy, style and placement for a formal syntax disclaimer.

@argl argl added p1 We will address this soon and will provide capacity from our team for it in the next few releases. and removed needs content decision labels Sep 24, 2025
@argl
Copy link
Contributor Author

argl commented Oct 2, 2025

Content decision is done, a PR adding the necessary translated text fragments is under review.

@argl argl removed the p1 We will address this soon and will provide capacity from our team for it in the next few releases. label Oct 2, 2025
@argl argl marked this pull request as ready for review October 7, 2025 08:47
@argl argl requested review from a team and mdn-bot as code owners October 7, 2025 08:47
@argl argl requested a review from caugner October 7, 2025 08:49

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct AtRule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that all these types share some fields, could these be extracted to a common base type, to ensure consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no classic inheritance in rust, and we are bound to the JSON-structure of the webref data, we cannot use a straight composition pattern (tying together shared attributes in a common sub-struct). Other ways to do inheritance (traits, enums) are also not helping with clarity here. I think the current structs are not overwhelmingly large and changes are comparatively few.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered struct flattening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I decided against it. For consistency we would have to change a lot of structs that are outside the scope of this change. I would recommend to do that in a separate PR if really needed.

@argl argl requested a review from caugner October 7, 2025 15:17
@caugner caugner changed the title chore(css): webref css version 7 support feat(css-syntax): migrate to @webref/css 7 Oct 7, 2025
Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass.


#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct AtRule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered struct flattening?

}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AtruleDescriptor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Rename to AtRuleDescriptor for consistency.

Suggested change
pub struct AtruleDescriptor {
pub struct AtRuleDescriptor {

}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum Interfacetype {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub enum Interfacetype {
pub enum InterfaceType {

Ok(url_to_title)
}

fn url_to_title_map(base_path: &Path) -> Result<BTreeMap<String, String>, DepsError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Add a short comment with an example of what the resulting map contains. Also possibly rename to spec_url_to_title_map.

Suggested change
fn url_to_title_map(base_path: &Path) -> Result<BTreeMap<String, String>, DepsError> {
fn spec_url_to_title_map(base_path: &Path) -> Result<BTreeMap<String, String>, DepsError> {

Comment on lines 208 to 212
let url_to_title = url_to_title_map(base_path)?;

// Process the CSS data with the URL-to-title map passed in.
if let Some(package_path) = get_package("@webref/css", &deps().webref_css, base_path)? {
let webref_css = transform(&package_path, &url_to_title)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Move url_to_title inside block.

Suggested change
let url_to_title = url_to_title_map(base_path)?;
// Process the CSS data with the URL-to-title map passed in.
if let Some(package_path) = get_package("@webref/css", &deps().webref_css, base_path)? {
let webref_css = transform(&package_path, &url_to_title)?;
// Process the CSS data with the URL-to-title map passed in.
if let Some(package_path) = get_package("@webref/css", &deps().webref_css, base_path)? {
let url_to_title = url_to_title_map(base_path)?;
let webref_css = transform(&package_path, &url_to_title)?;

@argl argl requested a review from caugner October 9, 2025 15:36
Comment on lines 114 to 128
// // In order to use it with in a BtreeSet<SpecLink>, implement `PartialOrd` and `Ord`
// impl PartialOrd for SpecLink {
// fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
// Some(self.cmp(other))
// }
// }

impl Ord for SpecLink {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
// First compare by title, then by URL if titles are equal
self.title
.cmp(&other.title)
.then_with(|| self.url.cmp(&other.url))
}
}
// impl Ord for SpecLink {
// fn cmp(&self, other: &Self) -> std::cmp::Ordering {
// // First compare by title, then by URL if titles are equal
// self.title
// .cmp(&other.title)
// .then_with(|| self.url.cmp(&other.url))
// }
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can't we just remove?

Suggested change
// // In order to use it with in a BtreeSet<SpecLink>, implement `PartialOrd` and `Ord`
// impl PartialOrd for SpecLink {
// fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
// Some(self.cmp(other))
// }
// }
impl Ord for SpecLink {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
// First compare by title, then by URL if titles are equal
self.title
.cmp(&other.title)
.then_with(|| self.url.cmp(&other.url))
}
}
// impl Ord for SpecLink {
// fn cmp(&self, other: &Self) -> std::cmp::Ordering {
// // First compare by title, then by URL if titles are equal
// self.title
// .cmp(&other.title)
// .then_with(|| self.url.cmp(&other.url))
// }
// }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, missed a file save there.

@argl argl merged commit b011b7d into main Oct 14, 2025
5 checks passed
@caugner caugner deleted the webref-css7-support branch October 14, 2025 21:06
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.

Migrate to @webref/css v7

2 participants