Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ script:
- nosetests
- mincss https://news.ycombinator.com

branches:
only:
- master

deploy:
provider: pypi
user: peterbe
Expand Down
7 changes: 6 additions & 1 deletion mincss/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
RE_NESTS = re.compile('@(-|keyframes).*?({)', re.DOTALL | re.M)
RE_CLASS_DEF = re.compile('\.([\w-]+)')
RE_ID_DEF = re.compile('#([\w-]+)')
MOUSE_PSEUDO_CLASSES = re.compile(
':(link|hover|active|focus|visited)$', re.M | re.I
)


EXCEPTIONAL_SELECTORS = (
Expand Down Expand Up @@ -477,7 +480,9 @@ def _found(self, bodies, selector):
return r

def _selector_query_found(self, bodies, selector):
selector = selector.split(':')[0]
# If the select has something like :active or :hover
if MOUSE_PSEUDO_CLASSES.findall(selector) or '::' in selector:
selector = selector.split(':')[0]

if '}' in selector:
# XXX does this ever happen any more?
Expand Down
40 changes: 40 additions & 0 deletions tests/nth-child.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>test page</title>
<style>
a.nothere:hover { font-weight: bold; }
a.actually:hover { font-weight: bold; }

a.nothere:active { font-weight: bold; }
a.actually:active { font-weight: bold; }

a.nothere:link { font-weight: bold; }
a.actually:link { font-weight: bold; }

a.nothere:focus { font-weight: bold; }
a.actually:focus { font-weight: bold; }

a.nothere:visited { font-weight: bold; }
a.actually:visited { font-weight: bold; }

div > :first-child { color: pink; }
div > :last-child { color: brown; }
div > :not(p) { color: blue; }
div > :nth-child(2) { color: red; }
</style>
</head>
<body>
<h1>h1</h1>
<a href="@" class="actually">actually</a>
<div>
<p>First one</p>
<p>Second one</p>
<p>Third one</p>
<span>Fourth one</span>
<p>Fifth one</p>
</div>

</body>
</html>
20 changes: 20 additions & 0 deletions tests/test_mincss.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,23 @@ def test_make_absolute_url(self):
p.make_absolute_url('http://www.com/elsewhere', './style.css'),
'http://www.com/style.css'
)

def test_nth_child(self):
html = os.path.join(HERE, 'nth-child.html')
url = 'file://' + html
p = Processor()
p.process(url)
# print repr(p.inlines[0].before)
after = p.inlines[0].after
# These mouse related one should stay, even though they're
# currently NOT being acted upon with some input device.
ok_('a.actually:hover { font-weight: bold; }' in after)
ok_('a.actually:visited { font-weight: bold; }' in after)
ok_('a.actually:link { font-weight: bold; }' in after)
ok_('a.actually:focus { font-weight: bold; }' in after)
ok_('a.actually:active { font-weight: bold; }' in after)
# the other selectors with : in them should also stay
ok_('div > :first-child { color: pink; }' in after)
ok_('div > :last-child { color: brown; }' in after)
ok_('div > :not(p) { color: blue; }' in after)
ok_('div > :nth-child(2) { color: red; }' in after)