Permalink
Browse files

Fix bug when child selectors are used.

  • Loading branch information...
1 parent 854db04 commit 03ae793f9165623f3357d7a48ab62a41ce16b0d9 @bradleyayers bradleyayers committed May 28, 2012
Showing with 34 additions and 3 deletions.
  1. +1 −3 premailer/premailer.py
  2. +33 −0 premailer/test_premailer.py
View
@@ -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()
@@ -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 03ae793

Please sign in to comment.