Browse files

Merge pull request #19 from bradleyayers/master

Fix bug that prevents child selectors from being used in CSS
  • Loading branch information...
2 parents 854db04 + 03ae793 commit cbb01ad8b473ea348383e06bf0a78c1108074f50 @peterbe committed May 29, 2012
Showing with 34 additions and 3 deletions.
  1. +1 −3 premailer/premailer.py
  2. +33 −0 premailer/test_premailer.py
View
4 premailer/premailer.py
@@ -160,9 +160,7 @@ def transform(self, pretty_print=True):
rules = []
for style in CSSSelector('style')(page):
- css_body = etree.tostring(style)
- css_body = css_body.split('>')[1].split('</')[0]
- these_rules, these_leftover = self._parse_style_rules(css_body)
+ these_rules, these_leftover = self._parse_style_rules(style.text)
rules.extend(these_rules)
parent_of_style = style.getparent()
View
33 premailer/test_premailer.py
@@ -668,3 +668,36 @@ def test_mediaquery():
result_html = whitespace_between_tags.sub('><', result_html).strip()
eq_(expect_html, result_html)
+
+
+def test_child_selector():
+ html = """<html>
+ <head>
+ <style type="text/css">
+ body > div {
+ text-align: right;
+ }
+ </style>
+ </head>
+ <body>
+ <div>First div</div>
+ </body>
+ </html>"""
+
+ expect_html = """<html>
+ <head>
+ </head>
+ <body>
+ <div style="text-align:right" align="right">First div</div>
+ </body>
+ </html>"""
+
+ p = Premailer(html)
+ result_html = p.transform()
+
+ whitespace_between_tags = re.compile('>\s*<',)
+
+ expect_html = whitespace_between_tags.sub('><', expect_html).strip()
+ result_html = whitespace_between_tags.sub('><', result_html).strip()
+
+ eq_(expect_html, result_html)

0 comments on commit cbb01ad

Please sign in to comment.