Page MenuHomePhabricator

Automatic Correction of Template and Inline Styles
Closed, DeclinedPublic

Description

Create a solution to automatically corrects template and inline styles that do not comply with night mode standards. This includes identifying styles that specify a background color without a corresponding text color and applying a suitable text color. The task involves algorithm development, testing across different articles and templates, and implementing a safe deployment strategy to minimize disruption.

There again a number of different paths:

  • If you use the ParserOutputPostCacheTransform hook you will get output from both Parsoid and the legacy parser, and because this is post-cache it won't affect the HTML served to VisualEditor, etc and so you're not likely to corrupt other downstream clients. But because this is post-cache, whatever transformation you write should be as efficient as possible. (There are still edge caches in front of this, so it's not after *all* caching, but its still fairly performance-sensitive.)
    • A variation of this just adds a class marker to any tag which defines a style attribute, in order to make a client-side [style*="color"] { ... } stylesheet more efficient, eg: .mw-defines-style[style*="color"] { ... }
  • Modifying TemplateStyles is technically the cleanest, but of course only affects TemplateStyles
  • In an ideal world, Sanitizer::checkCSS in core would use the same css-sanitizer library that TemplateStyles does, which would make any CSS mutation more technically clean, but this is probably a heavier lift than we'd like to tackle right now, especially since we'd have to consider the comparative performance of css-sanitizer versus the regexp that core uses.

Related Objects

Event Timeline

Sanitizer::checkCSS in core would use the same css-sanitizer library that TemplateStyles does, which would make any CSS mutation more technically clean, but this is probably a heavier lift than we'd like to tackle right now, especially since we'd have to consider the comparative performance of css-sanitizer versus the regexp that core uses.

I have thought about this one and realized it's not workable. CSS sanitizer does not get nearly enough attention for new properties and new values, and CSS standards do not move nearly fast enough through the standards track, to hook it in as the backend for the parser's sanitizer of inline styles, which serve as a useful release valve/currently supported workaround for properties and values unsupported by that library.

Jdlrobson changed the task status from Open to Stalled.EditedFeb 29 2024, 6:22 PM

We are likely to go with a CSS-only solution (T358797) and decline this work.

Given the CSS only solution this is not needed.