Skip to content
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

CSS improvements #45

Merged
merged 1 commit into from
Nov 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
0.10.0 (?)
------------------

- fix CSS child selectors
- disable loading remote stylesheets
- require css-inline 0.11.x for performance improvements
- drop css-inline Python 3.6 support
- fix exception when processing an `mj-section` with `background-size` (reported by Thomas Handorf)
Expand Down
5 changes: 3 additions & 2 deletions mjml/mjml2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def parse(_mjml, parentMjClass='', *, template_dir):
classes = ignore_empty(attributes.get('mj-class', '').split(' '))

# upstream parses text contents (+ comments) in mjml-parser-xml/index.js
content = _mjml.decode_contents()
content = _mjml.decode_contents(formatter=None)

attributesClasses = {}
for css_class in classes:
Expand Down Expand Up @@ -212,7 +212,7 @@ def _head_data_add(attr, *params):
for element in contentSoup.select(selector):
element[attrName] = value or ''

content = contentSoup.decode_contents()
content = contentSoup.decode_contents(formatter=None)

content = skeleton(
content=content,
Expand All @@ -235,6 +235,7 @@ def _head_data_add(attr, *params):
inline_style_tags=False,
keep_link_tags=True,
keep_style_tags=True,
load_remote_stylesheets=False,
)
content = inliner.inline(content)

Expand Down
2 changes: 1 addition & 1 deletion tests/testdata/css-inlining-expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
</tr>
<tr>
<td align="left" class="box" style="border: 5px solid red; font-size: 0px; padding: 10px 25px; word-break: break-word;">
<div style="font-family:helvetica;font-size:20px;line-height:1;text-align:left;color:#F45E43;">Hello World</div>
<div style="font-family:helvetica;font-size:20px;line-height:1;text-align:left;color:#F45E43;"><span style="border: 3px solid blue;"> &lt; Hello World &gt; </span></div>
</td>
</tr>
</tbody>
Expand Down
9 changes: 8 additions & 1 deletion tests/testdata/css-inlining.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
.box {
border: 5px solid red;
}
.box > div > span {
border: 3px solid blue;
}
</mj-style>
</mj-head>
<mj-body>
Expand All @@ -14,7 +17,11 @@

<mj-divider border-color="#F45E43"></mj-divider>

<mj-text css-class="box" font-size="20px" color="#F45E43" font-family="helvetica">Hello World</mj-text>
<mj-text css-class="box" font-size="20px" color="#F45E43" font-family="helvetica">
<span>
&lt; Hello World &gt;
</span>
</mj-text>

</mj-column>
</mj-section>
Expand Down