Skip to content

Commit

Permalink
Fix CSS child selectors; don't load remote stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyjhol authored and FelixSchwarz committed Nov 17, 2023
1 parent 3308bba commit 84c495d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
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

0 comments on commit 84c495d

Please # to comment.