module Text.HTML.Tagchup.Tag.Match where
import qualified Text.HTML.Tagchup.Tag as Tag
import qualified Text.XML.Basic.Attribute as Attr
import qualified Text.XML.Basic.Name as Name
ignore :: a -> Bool
ignore _ = True
open ::
(Tag.Name name -> Bool) -> ([Attr.T name string] -> Bool) ->
Tag.T name string -> Bool
open pName pAttrs (Tag.Open name attrs) = pName name && pAttrs attrs
open _ _ _ = False
close :: (Tag.Name name -> Bool) -> Tag.T name string -> Bool
close pName (Tag.Close name) = pName name
close _ _ = False
text :: (string -> Bool) -> Tag.T name string -> Bool
text p (Tag.Text str) = p str
text _ _ = False
comment :: (String -> Bool) -> Tag.T name string -> Bool
comment p (Tag.Comment str) = p str
comment _ _ = False
special :: (Tag.Name name -> Bool) -> (String -> Bool) -> Tag.T name string -> Bool
special pType pInfo (Tag.Special typ info) = pType typ && pInfo info
special _ _ _ = False
openLit ::
(Name.Tag name) =>
String -> ([Attr.T name string] -> Bool) -> Tag.T name string -> Bool
openLit name = open (Name.match name)
closeLit ::
(Name.Tag name) =>
String -> Tag.T name string -> Bool
closeLit name = close (Name.match name)
openAttrLit ::
(Name.Attribute name, Name.Tag name, Eq string) =>
String -> String -> string -> Tag.T name string -> Bool
openAttrLit name attrName attrValue =
openLit name (Attr.anyLit attrName attrValue)
openAttrNameLit ::
(Name.Attribute name, Name.Tag name) =>
String -> String -> (string -> Bool) -> Tag.T name string -> Bool
openAttrNameLit tagName attrName pAttrValue =
openLit tagName
(Attr.any (\(Attr.Cons name value) ->
Name.match attrName name && pAttrValue value))
openNameLit ::
(Name.Tag name) =>
String -> Tag.T name string -> Bool
openNameLit name = openLit name ignore
closeNameLit ::
(Name.Tag name) =>
String -> Tag.T name string -> Bool
closeNameLit name = closeLit name