Skip to content

Commit 60258a3

Browse files
committed
before and after pseudoclasses
1 parent a8d5dc6 commit 60258a3

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

mincss/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.11.0'
1+
__version__ = '0.11.1'

mincss/processor.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
MOUSE_PSEUDO_CLASSES = re.compile(
3737
':(link|hover|active|focus|visited)$', re.M | re.I
3838
)
39+
BEFOREAFTER_PSEUDO_CLASSES = re.compile(
40+
':(before|after)$', re.M | re.I
41+
)
3942

4043

4144
EXCEPTIONAL_SELECTORS = (
@@ -480,8 +483,13 @@ def _found(self, bodies, selector):
480483
return r
481484

482485
def _selector_query_found(self, bodies, selector):
483-
# If the select has something like :active or :hover
484-
if MOUSE_PSEUDO_CLASSES.findall(selector) or '::' in selector:
486+
# If the select has something like :active or :hover,
487+
# then evaluate it as if it's without that pseudo class
488+
if (
489+
MOUSE_PSEUDO_CLASSES.findall(selector) or
490+
'::' in selector or
491+
BEFOREAFTER_PSEUDO_CLASSES.findall(selector)
492+
):
485493
selector = selector.split(':')[0]
486494

487495
if '}' in selector:

tests/before-after.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset='utf-8'>
5+
<title>test page</title>
6+
<style>
7+
ol li:before { content: "x"; }
8+
ul li:after { content: "x"; }
9+
</style>
10+
</head>
11+
<body>
12+
<ol>
13+
<li>First</li>
14+
<li>Second</li>
15+
</ol>
16+
</body>
17+
</html>

tests/test_mincss.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,12 @@ def test_complex_colons_in_selector_expression(self):
342342
after = p.inlines[0].after
343343
ok_('a[href^="javascript:"] { color: pink; }' in after)
344344
ok_('a[href^="javascript:"]:after { content: "x"; }' in after)
345+
346+
def test_before_after(self):
347+
html = os.path.join(HERE, 'before-after.html')
348+
url = 'file://' + html
349+
p = Processor()
350+
p.process(url)
351+
after = p.inlines[0].after
352+
ok_('ul li:after { content: "x"; }' not in after)
353+
ok_('ol li:before { content: "x"; }' in after)

0 commit comments

Comments
 (0)