Skip to content

Conversation

@8ctopus
Copy link
Contributor

@8ctopus 8ctopus commented Dec 25, 2025

Hello guys, happy holidays :) Please don't review the PR until after the festivities, I'm just not that type of person.

This PR draft aims at converting the legacy color notation: rgba(0,128,0,.7) into the modern variant rgba(0 128 0/.7).

I'm no css specialist so your feedback is going to be welcome.

There are no specific tests yet, and there are improvements that can be made, I just want to get your approval before I polish things up.

Question:

  • should we also convert the rgba notation to rgb? my understanding is that rgba is deprecated. I also noticed that the current code does the opposite:
a {
   color: rgb(0 0 0/50%);
}

into this:

a {
   color: rgba(0 0 0/50%);
}

Copy link
Collaborator

@JakeQZ JakeQZ left a comment

Choose a reason for hiding this comment

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

Hello guys, happy holidays :)

Thanks 🎄

This PR draft aims at converting the legacy color notation: rgba(0,128,0,.7) into the modern variant rgba(0 128 0/.7).

Some users may want the rendered output to stay in the legacy notation for compatibility or other reasons. (For example the version of markdown used by GitHub only recognizes the legacy syntax for showing the actual colour alongside the value in backticks.)

So I think this should be controllable via an OutputFormat option similar to setRGBHashNotation(), with the default being to use the legacy syntax (so there are no breaking changes). For the next major release we can change the default.

there are improvements that can be made

The simplest way of implementing this is for Color::shouldRenderInModernSyntax() to immediately return true if the modern syntax option is enabled in the OutputFormat.

  • should we also convert the rgba notation to rgb? my understanding is that rgba is deprecated.

It's not currently deprecated; the two are synonymous, but it is now "recommended" to use rgb().

I think if the modern syntax option is enabled then rgb() should always be used, but otherwise the current behaviour should be retained (previously rgba() was required when there is an alpha value).

I also noticed that the current code does the opposite:

That's not quite the case. It uses rgb() if there's no alpha value, but rgba() if there is one.

There are no specific tests yet

Note that this change will (should) similarly affect hsl(), so some tests would also be needed for those colour functions.

@oliverklee, WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants