-- | Combinators to match tags. Some people prefer to use @(~==)@ from-- "Text.HTML.TagSoup", others prefer these more structured combinators.-- Which you use is personal preference.moduleText.HTML.TagSoup.MatchwhereimportText.HTML.TagSoup.Type(Tag(..),Attribute)importData.List-- | match an opening tagtagOpen::(str->Bool)->([Attributestr]->Bool)->Tagstr->BooltagOpenpNamepAttrs(TagOpennameattrs)=pNamename&&pAttrsattrstagOpen___=False-- | match an closing tagtagClose::(str->Bool)->Tagstr->BooltagClosepName(TagClosename)=pNamenametagClose__=False-- | match a texttagText::(str->Bool)->Tagstr->BooltagTextp(TagTexttext)=ptexttagText__=FalsetagComment::(str->Bool)->Tagstr->BooltagCommentp(TagCommenttext)=ptexttagComment__=False-- | match a opening tag's name literallytagOpenLit::Eqstr=>str->([Attributestr]->Bool)->Tagstr->BooltagOpenLitname=tagOpen(name==)-- | match a closing tag's name literallytagCloseLit::Eqstr=>str->Tagstr->BooltagCloseLitname=tagClose(name==)tagOpenAttrLit::Eqstr=>str->Attributestr->Tagstr->BooltagOpenAttrLitnameattr=tagOpenLitname(anyAttrLitattr){- |
Match a tag with given name, that contains an attribute
with given name, that satisfies a predicate.
If an attribute occurs multiple times,
all occurrences are checked.
-}tagOpenAttrNameLit::Eqstr=>str->str->(str->Bool)->Tagstr->BooltagOpenAttrNameLittagNameattrNamepAttrValue=tagOpenLittagName(anyAttr(\(name,value)->name==attrName&&pAttrValuevalue))-- | Check if the 'Tag str' is 'TagOpen' and matches the given nametagOpenNameLit::Eqstr=>str->Tagstr->BooltagOpenNameLitname=tagOpenLitname(constTrue)-- | Check if the 'Tag str' is 'TagClose' and matches the given nametagCloseNameLit::Eqstr=>str->Tagstr->BooltagCloseNameLitname=tagCloseLitnameanyAttr::((str,str)->Bool)->[Attributestr]->BoolanyAttr=anyanyAttrName::(str->Bool)->[Attributestr]->BoolanyAttrNamep=any(p.fst)anyAttrValue::(str->Bool)->[Attributestr]->BoolanyAttrValuep=any(p.snd)anyAttrLit::Eqstr=>(str,str)->[Attributestr]->BoolanyAttrLitattr=anyAttr(attr==)anyAttrNameLit::Eqstr=>str->[Attributestr]->BoolanyAttrNameLitname=anyAttrName(name==)anyAttrValueLit::Eqstr=>str->[Attributestr]->BoolanyAttrValueLitvalue=anyAttrValue(value==)getTagContent::Eqstr=>str->([Attributestr]->Bool)->[Tagstr]->[Tagstr]getTagContentnamepAttrs=takeWhile(not.tagCloseLitname).drop1.head.sections(tagOpenLitnamepAttrs)wheresectionsp=filter(p.head).init.tails