@@ 6,12 6,14 @@ module Data.CSS.Style.Selector.LowerWhere(
import Data.CSS.Syntax.Selector
import Data.CSS.Style.Common
-lowerSelector :: Selector -> Selector
-lowerSelector (Element sel) = Element $ lowerSelector' sel
-lowerSelector (Child sel x) = Child (lowerSelector sel) x
-lowerSelector (Descendant sel x) = Descendant (lowerSelector sel) x
-lowerSelector (Adjacent sel x) = Adjacent (lowerSelector sel) x
-lowerSelector (Sibling sel x) = Sibling (lowerSelector sel) x
+lowerSelector :: Selector -> [Selector]
+lowerSelector (Element [Psuedoclass c args])
+ | c `elem` ["is", "where"], (args', []) <- parseSelectors args = args'
+lowerSelector (Element sel) = [Element $ lowerSelector' sel]
+lowerSelector (Child sel x) = [Child sel' $ lowerSelector' x | sel' <- lowerSelector sel]
+lowerSelector (Descendant sel x) = [Descendant sel' $ lowerSelector' x | sel' <- lowerSelector sel]
+lowerSelector (Adjacent sel x) = [Adjacent sel' $ lowerSelector' x | sel' <- lowerSelector sel]
+lowerSelector (Sibling sel x) = [Sibling sel' $ lowerSelector' x | sel' <- lowerSelector sel]
lowerSelector' :: [SimpleSelector] -> [SimpleSelector]
lowerSelector' (Psuedoclass c args:sel)
@@ 25,8 27,10 @@ data WhereLowerer s = WhereLowerer s
instance RuleStore s => RuleStore (WhereLowerer s) where
new = WhereLowerer new
addStyleRule (WhereLowerer self) priority rule =
- WhereLowerer $ addStyleRule self priority $ rule {
- inner = StyleRule (lowerSelector sel) props psuedo
+ WhereLowerer $ foldl addStyleRule' self $ lowerSelector sel
+ where
+ addStyleRule' self' sel' = addStyleRule self' priority $ rule {
+ inner = StyleRule sel' props psuedo
}
- where StyleRule sel props psuedo = inner rule
+ StyleRule sel props psuedo = inner rule
lookupRules (WhereLowerer self) el = lookupRules self el