~alcinnz/amphiarao

5eb4b914899a44b795ab2df865781f08f6f64e2c — Adrian Cochrane 3 years ago b8351f8
Add search by tag name to JSON interface.

(Search by CSS selector seems close enough in the HTML interface that this wouldn't be useful.
1 files changed, 2 insertions(+), 0 deletions(-)

M src/Internal/Elements.hs
M src/Internal/Elements.hs => src/Internal/Elements.hs +2 -0
@@ 18,6 18,7 @@ import qualified XML.Selectors.CSS as CSS

import Network.URI (parseURIReference)
import Data.Maybe
import Data.String (fromString)

getTitle :: Session -> IO Text
getTitle session = getTitle' <$> documentRoot <$> document <$> readMVar session


@@ 44,6 45,7 @@ find (Find "css selector" sel) root = case CSS.parsePath sel of
    Left msg -> Left (True, msg)
find (Find "link text" sel) root = Right $ allLinks (== pack sel) root
find (Find "partial link text" sel) root = Right $ allLinks (Txt.isInfixOf $ pack sel) root
find (Find "tag name" sel) root = Right (X.descendant root >>= X.checkName (== fromString sel))
find (Find type_ _) _ = Left (False, "Invalid selector type: " ++ Txt.unpack type_)

allLinks test = X.descendant X.>=>