File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ data Selector
5454 | ByAttrContains Text Text
5555 | ByAttrStarts Text Text
5656 | ByAttrEnds Text Text
57- | Asterisk -- TODO: This needs to be deep.
57+ | Asterisk
5858 deriving (Show , Eq )
5959
6060
@@ -78,14 +78,14 @@ parseQuery = parseOnly cssQuery
7878
7979-- Below this line is the Parsec parser for css queries.
8080cssQuery :: Parser [[SelectorGroup ]]
81- cssQuery = many (char ' ' ) >> sepBy rules (char ' ,' >> many (char ' ' ))
81+ cssQuery = ( many (char ' ' ) >> sepBy rules (char ' ,' >> many (char ' ' ) ))
8282
8383rules :: Parser [SelectorGroup ]
8484rules = many $ directChildren <|> deepChildren
8585
8686directChildren :: Parser SelectorGroup
8787directChildren =
88- string " > " >> ( many (char ' ' ) ) >> DirectChildren <$> pOptionalTrailingSpace parseSelectorTypes
88+ string " > " >> many (char ' ' ) >> DirectChildren <$> pOptionalTrailingSpace parseSelectorTypes
8989
9090deepChildren :: Parser SelectorGroup
9191deepChildren = pOptionalTrailingSpace $ DeepChildren <$> parseSelectorTypes
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ runQuery html query = concatMap (runGroup html) query
8989runGroup :: Cursor -> [SelectorGroup ] -> [Cursor ]
9090runGroup c [] = [c]
9191runGroup c (DirectChildren s: gs) = concatMap (flip runGroup gs) $ c $/ selectors s
92- runGroup c (DeepChildren s: gs) = concatMap (flip runGroup gs) $ c $// selectors s
92+ runGroup c (DeepChildren s: gs) = concatMap (flip runGroup gs) $ c $. // selectors s
9393
9494selectors :: [SelectorType ] -> Cursor -> [Cursor ]
9595selectors cs c
@@ -125,7 +125,9 @@ selector c (ByAttrEnds n v) =
125125 case attribute (Name n Nothing Nothing ) c of
126126 t: _ -> v `T.isSuffixOf` t
127127 [] -> False
128- selector _ Asterisk = True
128+ selector c Asterisk = case node c of
129+ NodeElement _ -> True
130+ _ -> False
129131
130132pseudoselector :: Cursor -> Selector -> PseudoSelector -> Bool
131133pseudoselector c _ FirstChild = null $ precedingSibling c
Original file line number Diff line number Diff line change @@ -130,6 +130,8 @@ main = hspec $ do
130130 findBySelector_ html " p:nth-child(-n-1)" @?= []
131131 findBySelector_ html " p:nth-child(-n-0)" @?= []
132132 findBySelector_ html " p:nth-child(-n+3)" @?= [" <p>1</p>" , " <p>2</p>" , " <p>3</p>" ]
133+ let ps = [" <p>" <> show n <> " </p>" | n <- [1 .. 10 ]] in
134+ findBySelector_ html " *" @?= [" <html>" <> concat ps <> " </html>" ] <> ps
133135
134136 describe " HTML parsing" $ do
135137 it " XHTML" $
Original file line number Diff line number Diff line change 11name : yesod-test
2- version : 1.6.23.1
2+ version : 1.6.24
33license : MIT
44license-file : LICENSE
55
You can’t perform that action at this time.
0 commit comments