-
Notifications
You must be signed in to change notification settings - Fork 14
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
InlineCssPostProcessor overwrites default tag styles #203
Comments
Hi, what do you mean with "default" styles? |
Things such as these
I came to this conclusion, as texts in my email which are longer than 600px now overflow way outside their container. I then noticed that for example |
Good point, I think it is easy to fix. Just don#t overwrite styles that already exist I guess (except they are important) |
@SebastianStehle I already gave it a shot with: private static void InlineStyle(IElement element, IStyleCollection styleCollection)
{
var currentStyle = styleCollection.GetDeclarations(element);
if (!currentStyle.Any())
{
return;
}
var style = element.GetStyle();
foreach (var property in currentStyle)
{
style.SetProperty(property.Name, property.Value, property.IsImportant ? CssKeywords.Important : null);
} However, I still had the issue that |
Weird, perhaps there is another method that helps? |
I am not sure if I understand the bug tbh. I have this test:
Here font-weight is not overriden. Because GetDeclarations actually calculates the styles in the correct logic. How would that override styles from mjml? |
@SebastianStehle look at this modified variant of the the test [Fact]
public async Task Should_render_inline()
{
var source = @"
<mjml-test>
<mj-head>
<mj-style inline=""inline"">
.red-text div {
color: red !important;
font-size: 1.5rem;
}
</mj-style>
</mj-head>
<mj-body>
<mj-raw>
<div class=""red-text"">
<div style=""font-weight: bold; word-break: break-word;""></div>
</div>
</mj-raw>
</mj-body>
</mjml-test>
";
var (result, _) = await TestHelper.RenderAsync(source, new MjmlOptions
{
PostProcessors =
[
AngleSharpPostProcessor.Default
],
Beautify = true
}, helpers: [new StyleHelper()]);
AssertHelpers.HtmlFileAssert("Components.Outputs.StyleInline.html", result);
} I just added the
And the test is still green! I can also verify that I guess it has something to do with the css property itself then? |
For me it looks like it just ignores most CSS properties. |
I have tried to debug it in AngleSharp and created a bug report there. Lets see what happens |
@SebastianStehle Thank you very much. :) |
Since
v4
the newInlineCssPostProcessor
causes the default styles defined by mjml-net to be overwritten. I believe its caused on this line:mjml-net/Mjml.Net.PostProcessors/InlineCssPostProcessor.cs
Line 37 in 4aa0c64
From what I can tell this more or less ignores all styles defined on the
style=
attribute. For example callingelement.GetAttribute(TagNames.Style)
will correctly return meword-break:break-word
. Otherwise with the current implementation the wholeInlineCssPostProcessor
causes the whole HTML to be more or less broken.Would be awesome if you could take a look at it :). Also thanks for maintaining this library, it's awesome!
The text was updated successfully, but these errors were encountered: