Skip to content

Commit

Permalink
Fix inner border. Closes #204
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Sep 26, 2024
1 parent 4aa0c64 commit 43a0147
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<RepositoryUrl>https://github.com/SebastianStehle/mjml-net.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>4.3.0</Version>
<Version>4.4.0</Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Mjml.Net.Generator/TemplateField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed record TemplateField

public bool IsText { get; set; }

public bool IsBorder => Attribute == "border";
public bool IsBorder => Attribute is "border" or "inner-border";

public bool IsCustom => CustomType != null;
}
14 changes: 10 additions & 4 deletions Mjml.Net.PostProcessors/InlineCssPostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Css.Dom;
using AngleSharp.Dom;

namespace Mjml.Net;
Expand Down Expand Up @@ -36,12 +37,17 @@ private static void InlineStyle(IElement element)
{
var currentStyle = element.Owner!.DefaultView.GetStyleCollection().GetDeclarations(element);

if (currentStyle.Any())
if (!currentStyle.Any())
{
var css = currentStyle.ToCss();

element.SetAttribute(TagNames.Style, css);
return;
}

var cuirrent = element.GetStyle();
var x = element.GetStyleSheets();

var css = currentStyle.ToCss();

element.SetAttribute(TagNames.Style, css);
}

private static void RenameNonInline(IElement element, IDocument document)
Expand Down
15 changes: 15 additions & 0 deletions Tests/Components/ColumnTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,19 @@ public void Should_render_column_one_with_padding()

AssertHelpers.HtmlFileAssert("Components.Outputs.ColumnOneWithPadding.html", result);
}

[Fact]
public void Should_render_column_one_inner_border()
{
var source = @"
<mj-column padding=""0"" inner-border=""1px solid red"">
<mj-text>
Hello World!
</mj-text>
</mj-column>";

var (result, _) = TestHelper.Render(source);

AssertHelpers.HtmlFileAssert("Components.Outputs.ColumnOneWithInnerBorder.html", result);
}
}
6 changes: 1 addition & 5 deletions Tests/Components/StyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ public async Task Should_render_inline()
<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""></div>
<div style=""word-break: break-word; font-weight: bold; font-style: abc;""></div>
</div>
</mj-raw>
</mj-body>
Expand Down
2 changes: 2 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<None Remove="Components\Outputs\CarouselImageWithHref.html" />
<None Remove="Components\Outputs\CarouselThumbnailWidth.html" />
<None Remove="Components\Outputs\ColumnClass.html" />
<None Remove="Components\Outputs\ColumnOneWithInnerBorder.html" />
<None Remove="Components\Outputs\Comments.html" />
<None Remove="Components\Outputs\DividerWithoutWidthUnit.html" />
<None Remove="Components\Outputs\FontUbuntu2.html" />
Expand Down Expand Up @@ -102,6 +103,7 @@
<EmbeddedResource Include="Components\Outputs\CarouselThumbnailWidth.html" />
<EmbeddedResource Include="Components\Outputs\AccordionEmptyElements.html" />
<EmbeddedResource Include="Components\Outputs\Accordion.html" />
<EmbeddedResource Include="Components\Outputs\ColumnOneWithInnerBorder.html" />
<EmbeddedResource Include="Components\Outputs\HtmlAttributeInvalid.html" />
<EmbeddedResource Include="Components\Outputs\HtmlAttributesNoProcessor.html" />
<EmbeddedResource Include="Components\Outputs\List.html" />
Expand Down

0 comments on commit 43a0147

Please sign in to comment.