From e6f9c354edd8214cd588e481e748a6f62f9d1d60 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Sat, 30 Jan 2016 22:09:54 -0500 Subject: [PATCH 1/2] accept pseudoclass selectors except mouse related --- mincss/processor.py | 7 ++++++- tests/nth-child.html | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_mincss.py | 20 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/nth-child.html diff --git a/mincss/processor.py b/mincss/processor.py index 1c7cb11..6165819 100644 --- a/mincss/processor.py +++ b/mincss/processor.py @@ -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 = ( @@ -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? diff --git a/tests/nth-child.html b/tests/nth-child.html new file mode 100644 index 0000000..6014e16 --- /dev/null +++ b/tests/nth-child.html @@ -0,0 +1,40 @@ + + + + + test page + + + +

h1

+ actually +
+

First one

+

Second one

+

Third one

+ Fourth one +

Fifth one

+
+ + + diff --git a/tests/test_mincss.py b/tests/test_mincss.py index b5f5858..2e6a449 100644 --- a/tests/test_mincss.py +++ b/tests/test_mincss.py @@ -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) From d075c04f7d56b1dd5c0cc59b6a52944251ea5d24 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Sat, 30 Jan 2016 22:11:08 -0500 Subject: [PATCH 2/2] only run tests on master --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4f72128..4de1ad4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,10 @@ script: - nosetests - mincss https://news.ycombinator.com +branches: + only: + - master + deploy: provider: pypi user: peterbe