module Text.HTML.TagSoup.Match where
import Text.HTML.TagSoup.Type (Tag(..), Attribute)
import Data.List (tails)
tagOpen :: (str -> Bool) -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpen :: forall str.
(str -> Bool) -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpen str -> Bool
pName [Attribute str] -> Bool
pAttrs (TagOpen str
name [Attribute str]
attrs) =
str -> Bool
pName str
name Bool -> Bool -> Bool
&& [Attribute str] -> Bool
pAttrs [Attribute str]
attrs
tagOpen str -> Bool
_ [Attribute str] -> Bool
_ Tag str
_ = Bool
False
tagClose :: (str -> Bool) -> Tag str -> Bool
tagClose :: forall str. (str -> Bool) -> Tag str -> Bool
tagClose str -> Bool
pName (TagClose str
name) = str -> Bool
pName str
name
tagClose str -> Bool
_ Tag str
_ = Bool
False
tagText :: (str -> Bool) -> Tag str -> Bool
tagText :: forall str. (str -> Bool) -> Tag str -> Bool
tagText str -> Bool
p (TagText str
text) = str -> Bool
p str
text
tagText str -> Bool
_ Tag str
_ = Bool
False
tagComment :: (str -> Bool) -> Tag str -> Bool
str -> Bool
p (TagComment str
text) = str -> Bool
p str
text
tagComment str -> Bool
_ Tag str
_ = Bool
False
tagOpenLit :: Eq str => str -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpenLit :: forall str.
Eq str =>
str -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpenLit str
name = forall str.
(str -> Bool) -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpen (str
nameforall a. Eq a => a -> a -> Bool
==)
tagCloseLit :: Eq str => str -> Tag str -> Bool
tagCloseLit :: forall str. Eq str => str -> Tag str -> Bool
tagCloseLit str
name = forall str. (str -> Bool) -> Tag str -> Bool
tagClose (str
nameforall a. Eq a => a -> a -> Bool
==)
tagOpenAttrLit :: Eq str => str -> Attribute str -> Tag str -> Bool
tagOpenAttrLit :: forall str. Eq str => str -> Attribute str -> Tag str -> Bool
tagOpenAttrLit str
name Attribute str
attr =
forall str.
Eq str =>
str -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpenLit str
name (forall str. Eq str => (str, str) -> [(str, str)] -> Bool
anyAttrLit Attribute str
attr)
tagOpenAttrNameLit :: Eq str => str -> str -> (str -> Bool) -> Tag str -> Bool
tagOpenAttrNameLit :: forall str.
Eq str =>
str -> str -> (str -> Bool) -> Tag str -> Bool
tagOpenAttrNameLit str
tagName str
attrName str -> Bool
pAttrValue =
forall str.
Eq str =>
str -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpenLit str
tagName
(forall str. ((str, str) -> Bool) -> [(str, str)] -> Bool
anyAttr (\(str
name,str
value) -> str
nameforall a. Eq a => a -> a -> Bool
==str
attrName Bool -> Bool -> Bool
&& str -> Bool
pAttrValue str
value))
tagOpenNameLit :: Eq str => str -> Tag str -> Bool
tagOpenNameLit :: forall str. Eq str => str -> Tag str -> Bool
tagOpenNameLit str
name = forall str.
Eq str =>
str -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpenLit str
name (forall a b. a -> b -> a
const Bool
True)
tagCloseNameLit :: Eq str => str -> Tag str -> Bool
tagCloseNameLit :: forall str. Eq str => str -> Tag str -> Bool
tagCloseNameLit str
name = forall str. Eq str => str -> Tag str -> Bool
tagCloseLit str
name
anyAttr :: ((str,str) -> Bool) -> [Attribute str] -> Bool
anyAttr :: forall str. ((str, str) -> Bool) -> [(str, str)] -> Bool
anyAttr = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any
anyAttrName :: (str -> Bool) -> [Attribute str] -> Bool
anyAttrName :: forall str. (str -> Bool) -> [Attribute str] -> Bool
anyAttrName str -> Bool
p = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (str -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst)
anyAttrValue :: (str -> Bool) -> [Attribute str] -> Bool
anyAttrValue :: forall str. (str -> Bool) -> [Attribute str] -> Bool
anyAttrValue str -> Bool
p = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (str -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd)
anyAttrLit :: Eq str => (str,str) -> [Attribute str] -> Bool
anyAttrLit :: forall str. Eq str => (str, str) -> [(str, str)] -> Bool
anyAttrLit (str, str)
attr = forall str. ((str, str) -> Bool) -> [(str, str)] -> Bool
anyAttr ((str, str)
attrforall a. Eq a => a -> a -> Bool
==)
anyAttrNameLit :: Eq str => str -> [Attribute str] -> Bool
anyAttrNameLit :: forall str. Eq str => str -> [Attribute str] -> Bool
anyAttrNameLit str
name = forall str. (str -> Bool) -> [Attribute str] -> Bool
anyAttrName (str
nameforall a. Eq a => a -> a -> Bool
==)
anyAttrValueLit :: Eq str => str -> [Attribute str] -> Bool
anyAttrValueLit :: forall str. Eq str => str -> [Attribute str] -> Bool
anyAttrValueLit str
value = forall str. (str -> Bool) -> [Attribute str] -> Bool
anyAttrValue (str
valueforall a. Eq a => a -> a -> Bool
==)
getTagContent :: Eq str => str -> ([Attribute str] -> Bool) -> [Tag str] -> [Tag str]
getTagContent :: forall str.
Eq str =>
str -> ([Attribute str] -> Bool) -> [Tag str] -> [Tag str]
getTagContent str
name [Attribute str] -> Bool
pAttrs =
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall str. Eq str => str -> Tag str -> Bool
tagCloseLit str
name) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> [a] -> [a]
drop Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a. [a] -> a
head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {b}. (b -> Bool) -> [b] -> [[b]]
sections (forall str.
Eq str =>
str -> ([Attribute str] -> Bool) -> Tag str -> Bool
tagOpenLit str
name [Attribute str] -> Bool
pAttrs)
where sections :: (b -> Bool) -> [b] -> [[b]]
sections b -> Bool
p = forall a. (a -> Bool) -> [a] -> [a]
filter (b -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> a
head) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [a]
init forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> [[a]]
tails