-
Notifications
You must be signed in to change notification settings - Fork 119
Fix #410: Preserve !important tag in inlined styles #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
The newline at the end of file change was not intentional and is not needed for the functionality. It was an automatic formatting change that happened when editing the file. This doesn't affect the behavior of the code. |
The additional code is needed because the existing style merging logic doesn't properly handle The existing code applies all styles from the stylesheet and then checks if the resulting style attribute contains This additional logic specifically:
This is necessary to fix issue #410 where |
Can you make a unit test to prove this, then try to remove this new logic after writing the test. If the test still pass, the new logic can be discarded. |
Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
I've created a test case that reproduces the issue described in #410 and tested whether the additional logic in StyleClassApplier.cs is necessary. Test Results:
This proves that the additional logic is necessary to preserve the I've added a specific test case in PreMailerTests.cs that reproduces the exact scenario from issue #410 to ensure this behavior is properly tested. |
Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
…ith descriptive name Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
I've addressed your feedback by:
The test now clearly conveys its purpose without referencing the issue number directly. |
…StyleResolver Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
I've moved the logic for preserving The changes:
All tests are still passing (152/152), confirming that the functionality is preserved. |
… add comprehensive tests Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
I've simplified the logic in Changes made:
The simplified approach:
All tests are passing (154/154), confirming that the functionality is preserved while making the code more maintainable. |
…lse if block Co-Authored-By: m@martinnormark.com <m@martinnormark.com>
I've further simplified the logic in Changes made:
This approach eliminates the duplication and makes the code more elegant while maintaining the same functionality. All tests are still passing (154/154). |
Preserve !important tag in inlined styles
This PR fixes issue #410 where the
!important
tag is being removed from inlined styles when using premailer.Problem
When a class matches a style, PreMailer.Net incorrectly removes
!important
from styles that are unrelated to the class being inlined.Example:
Input:
Output (incorrect):
Fix
The fix modifies the following:
CssElementStyleResolver.GetAllStyles()
to passemitImportant: true
when callingstyleClass.ToString()
, preserving the!important
flag in stylesheet styles.StyleClass.Merge
method to handle all cases correctly, ensuring that important styles are preserved during merging.StyleClassApplier.ApplyStyles
method to preserve the existing inline style with!important
when adding new styles.Testing
Added a test case to verify that
!important
tags are preserved in the inlined output.Link to Devin run: https://app.devin.ai/sessions/cdcd17119f824643ace0e832bba5701b
Requested by: m@martinnormark.com