MyIntervals / emogrifier

Converts CSS styles into inline style attributes in your HTML code.
https://www.myintervals.com/emogrifier.php
MIT License
904 stars 153 forks source link

!important should be preserved in inline styles #1260

Open seb303 opened 2 months ago

seb303 commented 2 months ago

Sometimes it is necessary to have inline styles include !important. For example to remove link underlining in Windows 10 Mail.

However, it seems that Emogrifier drops the !important when inlining the styles. I understand this may be necessary for pseudo-class overrides to work, so it's probably a good default behaviour. But could there be an option added to allow it to be preserved?

JakeQZ commented 2 months ago

I see this could be a useful option.

The !important is removed from inline styles because it is assumed all other rules have been applied inline, and therefore it is unncessariy, and could impact any additional CSS rules - it is impossible to override !important in an inline style.

Pseudo-class (and @media) rules currently don't work as well as they could - we are not adding !important so they are not overriding inline styles when perhaps they should. That is beyond the scope of this.

Would you be willing to create a PR for the option you propose, including tests?

JakeQZ commented 2 months ago

That said, if Windows 10 Mail uses additional CSS with !important, could you not supply some additional CSS to beat it, with higher specificity and also !important, or is it junking any CSS you provide?

(Windows Mail and Microsoft Outlook I know are terrible, but telling people not to use them is not an option.)

seb303 commented 2 months ago

Hi @JakeQZ

I'm not sure I have the experience (or time at the moment) to create a PR & tests, sorry.

Regarding overriding the CSS in another way: I guess we could add back another