diff --git a/premailer/premailer.py b/premailer/premailer.py index 7cfb186..0a8c40d 100644 --- a/premailer/premailer.py +++ b/premailer/premailer.py @@ -250,6 +250,9 @@ class Premailer(object): continue elif '*' in selector and not self.include_star_selectors: continue + elif selector.startswith(':'): + continue + # Crudely calculate specificity id_count = selector.count('#') class_count = selector.count('.') @@ -274,6 +277,7 @@ class Premailer(object): len(rules) # this is the rule's index number ) rules.append((specificity, selector, bulk)) + return rules, leftover def transform(self, pretty_print=True, **kwargs): @@ -401,6 +405,7 @@ class Premailer(object): else: selector = new_selector + assert selector sel = CSSSelector(selector) items = sel(page) if len(items): diff --git a/premailer/tests/test_premailer.py b/premailer/tests/test_premailer.py index dc7f2c1..fa5c2eb 100644 --- a/premailer/tests/test_premailer.py +++ b/premailer/tests/test_premailer.py @@ -2622,3 +2622,53 @@ sheet" type="text/css"> ) result_html = p.transform() compare_html(expect_html, result_html) + + def test_pseudo_selectors_without_selector(self): + """Happens when you have pseudo selectors without an actual selector. + Which means it's not possible to find it in the DOM. + + For example: + + + + Semantic-UI uses this in its normalizer. + + Original issue: https://github.com/peterbe/premailer/issues/184 + """ + + html = """ + + +

Hey

+ + """ + + expect_html = """ + + + + + +

Hey

+ + + """ + p = Premailer( + html, + exclude_pseudoclasses=False, + keep_style_tags=True, + ) + result_html = p.transform() + compare_html(expect_html, result_html)