Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
.idea/
.gradle/
build/
data/*.html
data/alfio/*.html
data/compiled/*.html
*.iml
*.ipr
*.iws
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions data/bug-mj-social.mjml → data/bugs/mj-social.mjml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- see https://github.com/digitalfondue/mjml4j/issues/7 -->
<mjml>
<mj-body>
<mj-section>
Expand Down
23 changes: 23 additions & 0 deletions data/bugs/section-border-none.mjml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<mjml>
<mj-head>
<mj-attributes>
<mj-section border-left="1px solid" border-right="1px solid" />
</mj-attributes>
</mj-head>
<mj-body>
<mj-section border-left="none" border-right="none">
<mj-column>
<mj-text>
This section should have no border.
</mj-text>
</mj-column>
</mj-section>
<mj-section>
<mj-column>
<mj-text>
This section should have left and right borders.
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
11 changes: 11 additions & 0 deletions data/bugs/social-inner-padding.mjml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-social inner-padding="9px">
<mj-social-element name="facebook"></mj-social-element>
</mj-social>
</mj-column>
</mj-section>
</mj-body>
</mjml>
Empty file added data/compiled/.keep
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- imported from issue https://github.com/SebastianStehle/mjml-net/issues/177 -->
<mjml>
<mj-body>
<mj-include path="include/styling.mjml" />
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
</mj-column>
</mj-section>
</mj-body>
</mjml>
</mjml>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
</mj-column>
</mj-section>

<mj-include path="/circular/circular-1.mjml" />
<mj-include path="/circular-1.mjml" />
</mj-body>
</mjml>
2 changes: 2 additions & 0 deletions data/invalid/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Put any mjml files that are not expected to compile in this directory so that they can be skipped by the nodejs
mjml compiler
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"mjml": "4.18.0"
},
"scripts": {
"build": "mjml data/*.mjml --config.beautify false -o data/"
"build":"mjml data/**/*.mjml --config.beautify false -o data/compiled/"
}
}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<version>6.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>6.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.graalvm.polyglot</groupId>
<artifactId>polyglot</artifactId>
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/ch/digitalfondue/mjml4j/BaseComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,17 @@ CssBoxModel getBoxModel() {
double getShorthandBorderValue(String attributeName, String direction) {
var mjAttributeDirection = getAttribute(attributeName + "-" + direction);
var mjAttribute = getAttribute(attributeName);

if (!Utils.isNullOrWhiteSpace(mjAttributeDirection)) {
return CssUnitParser.parse(mjAttributeDirection).value();
}

if (Utils.isNullOrWhiteSpace(mjAttribute)) {
return borderParser(mjAttributeDirection);
} else if (!Utils.isNullOrWhiteSpace(mjAttribute)) {
return borderParser(mjAttribute);
} else {
return 0;
}
}

// MERGED borderParser:
// https://github.com/mjmlio/mjml/blob/d4c6ea0744e05c928044108c3117c16a9c4110fe/packages/mjml-core/src/helpers/shorthandParser.js#L3
// return CssUnitParser.Parse(mjAttribute).Value;

var match = PATTERN_SHORTHAND_BORDER_VALUE.matcher(mjAttribute);
double borderParser(String borderValue) {
var match = PATTERN_SHORTHAND_BORDER_VALUE.matcher(borderValue);

if (!match.find()) return 0;

Expand Down
22 changes: 9 additions & 13 deletions src/main/java/ch/digitalfondue/mjml4j/MjmlComponentSocial.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import ch.digitalfondue.mjml4j.AttributeValueType.AttributeType;
import java.util.LinkedHashMap;
import java.util.Set;
import org.w3c.dom.Element;

class MjmlComponentSocial extends BaseComponent.BodyComponent {
Expand Down Expand Up @@ -58,9 +57,11 @@ StringBuilder renderMjml(HtmlRenderer renderer) {
: renderVertical(renderer);
}

private static final Set<String> INHERITING_ATTRIBUTES =
Set.of(
"border-radius",
@Override
String getInheritingAttribute(String attributeName) {
return switch (attributeName) {
case "padding" -> getAttribute("inner-padding");
case "border-radius",
"color",
"font-family",
"font-size",
Expand All @@ -69,17 +70,12 @@ StringBuilder renderMjml(HtmlRenderer renderer) {
"icon-height",
"icon-padding",
"icon-size",
"padding",
"line-height",
"text-padding",
"text-decoration");

@Override
String getInheritingAttribute(String attributeName) {
if ("padding".equals(attributeName)) {
attributeName = "inner-padding";
}
return INHERITING_ATTRIBUTES.contains(attributeName) ? getAttribute(attributeName) : null;
"text-decoration" ->
getAttribute(attributeName);
default -> null;
};
}

private StringBuilder renderVertical(HtmlRenderer renderer) {
Expand Down
Loading