Automattic / juice

Juice inlines CSS stylesheets into your HTML source.
MIT License
3.07k stars 216 forks source link

Dark-Mode in emailing (with juice) #469

Open kornelion opened 11 months ago

kornelion commented 11 months ago

Hi there,

I'm looking in a way to preserve the way dark-mode css code with juice for emailing generation.

In emailing, we have to cope with different email platforms, each handling the dark-mode differently.

While the @media (prefers-color-scheme) is working fine, we need to use other element to make it work with Microsoft Outlook for example :

[data-ogsc] .text{
 color: #ffffff!important;
}

And

[data-ogsb] .text{
 color: #ffffff!important;
}

But those declarations are stripped of when juice does its thing.

Any indication or update that can be made to avoid this ? Thanks !

cossssmin commented 6 months ago

Juice would need a 'safelist' option to define selectors that shouldn't be inlined. There is excludedProperties, but that is for things like 'padding' or 'display'.

Would be a great feature to add 👍

jrit commented 6 months ago

if you have control of what is css from a link and what is in a style tag, you can put the stuff you want to preserve in style and set removeStyleTags = false. or you can set up some postprocessing stuff to add these styles into your final html. dealing with rewrites that are not actually inlining css, like this is, tend to be not too bad