parent
5120e5624e
commit
5e85b9b2ac
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
||||
<style>
|
||||
:before{box-sizing:inherit}
|
||||
</style>
|
||||
|
||||
Semantic-UI uses this in its normalizer.
|
||||
|
||||
Original issue: https://github.com/peterbe/premailer/issues/184
|
||||
"""
|
||||
|
||||
html = """
|
||||
<html>
|
||||
<style>
|
||||
*,:after,:before{box-sizing:inherit}
|
||||
h1{ border: 1px solid blue}
|
||||
h1:hover {border: 1px solid green}
|
||||
|
||||
</style>
|
||||
<h1>Hey</h1>
|
||||
</html>
|
||||
"""
|
||||
|
||||
expect_html = """
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
*,:after,:before{box-sizing:inherit}
|
||||
h1{ border: 1px solid blue}
|
||||
h1:hover {border: 1px solid green}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="{border:1px solid blue} :hover{border:1px solid green}">Hey</h1>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
p = Premailer(
|
||||
html,
|
||||
exclude_pseudoclasses=False,
|
||||
keep_style_tags=True,
|
||||
)
|
||||
result_html = p.transform()
|
||||
compare_html(expect_html, result_html)
|
||||
|
|
Loading…
Reference in New Issue