Skip to content

Read bgcolor, font color and body text as legacy colors - #1344

Open
yangkx1024 wants to merge 1 commit into
DioxusLabs:mainfrom
yangkx1024:legacy-color-attributes
Open

yangkx1024 wants to merge 1 commit into
DioxusLabs:mainfrom
yangkx1024:legacy-color-attributes

Conversation

@yangkx1024

@yangkx1024 yangkx1024 commented Oct 30, 2026 •

Copy link
Copy Markdown

bgcolor only accepted #rgb and #rrggbb, and read #rgb without scaling each digit, so #fff became #0f0f0f. The white tables that HTML email is full of came out near black. Color names, hex without the #, and values with surrounding spaces were ignored, and <font color> and <body text> weren't mapped at all.

This parses them with Stylo's implementation of the HTML "rules for parsing a legacy colour value" (style::servo::attr::parse_legacy_color), the same module the dimension attributes already use, and maps font color and body text to color. body link/vlink would need :link state and are left out. bgcolor still applies to whichever elements it did before.

CI's WPT run covers css and svg only, which doesn't exercise these attributes, so I've added tests/blitz-tests/tests/legacy_color_attributes.rs. It compares each attribute against the equivalent CSS. The #fff and font color cases fail without the change.

I found this while using Blitz to render mail in an email client, and have been running it there from a fork.

`bgcolor` only took `#rgb` and `#rrggbb`, and read `#rgb` without
scaling each digit (`#fff` as `#0f0f0f`), so the white tables common in
email painted near black. Color names, hex digits without the `#` and
values with spaces around them were ignored.

Parse them with Stylo's implementation of the HTML "rules for parsing a
legacy colour value", as the dimension attributes already use Stylo's
parser, and map `font color` and `body text` to `color`, which were not
mapped at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yangkx1024
yangkx1024 marked this pull request as ready for review October 30, 2026 07:29

This branch has not been deployed

No deployments
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.

1 participant