HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduletagsoup-0.14.8Haskell2010

Text.HTML.TagSoup.Match

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.

The functions below offer maximum flexibility for matching tags. Using tagOpen, for example, you can match all links or buttons that have the "btn" class.

For simple uses cases—like matching all comment tags, or matching opening <a> tags, use the tag identification functions in Text.HTML.TagSoup#tag-identification.

  • 17 values
  • Packagetagsoup-0.14.8
  • Exports17
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceMatch.hs

Matching Tags

10 declarations
valuetagOpen :: (str -> Bool) -> ([Attribute str] -> Bool) -> Tag str -> Bool
#

Match an opening tag

Examples

Matching an opening <a> tag with a "btn" class:

Example2 expressions
let tag = TagOpen "a" [("class", "btn")]tagOpen (== "a") (\attrs -> any (== ("class", "btn")) attrs) tagTrue
valuetagClose :: (str -> Bool) -> Tag str -> Bool
#

Match a closing tag

Examples

Matching a closing </a> tag:

Example1 expression
tagClose (== "a") (TagClose "a")True
Example1 expression
tagClose (== "a") (TagOpen "a" [])False
valuetagText :: (str -> Bool) -> Tag str -> Bool
#

Match text tags

Examples

Match all text tags:

Example2 expressions
let tags = parseTags "<p>This is a paragraph</p>"[TagOpen "p" [],TagText "This is a paragraph",TagClose "p"]filter (tagText (const True)) tags[TagText "This is a paragraph"]
valuetagComment :: (str -> Bool) -> Tag str -> Bool
#

Match comment tags

Examples

Matching comment tags that include an exclamation mark:

Example2 expressions
let tags = parseTags "<!--This is a comment-->"[TagComment "This is a comment!"]all (tagComment (\s -> '!' `elem` s)) tagsTrue
valuetagOpenLit :: Eq str => str -> ([Attribute str] -> Bool) -> Tag str -> Bool
#

Match an opening tag's name literally

Examples

Matching <a> tags with the id "foo":

Example2 expressions
let tag = TagOpen "a" [("id", "foo")]TagOpen "a" [("id","foo")]tagOpenLit "a" (\attrs -> any (== ("id", "foo")) attrs) tagTrue
valuetagCloseLit :: Eq str => str -> Tag str -> Bool
#

Match a closing tag's name literally

Examples

Match a closing <a> tag:

Example1 expression
tagCloseLit "a" (TagClose "a")True
Example1 expression
tagCloseLit "a" (TagClose "em")False
valuetagOpenAttrLit :: Eq str => str -> Attribute str -> Tag str -> Bool
#

Match an opening tag's name literally, and at least one of its attributes

Examples

Matching a <div> tag with the id "foo":

Example1 expression
tagOpenAttrLit "div" ("id", "foo") (TagOpen "div" [("id", "foo")])True
valuetagOpenAttrNameLit
  1. :: Eq str
  2. => str
  3. -> str
  4. -> str -> Bool
  5. -> Tag str
  6. -> Bool
#

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.

Examples

Matching an <a> tag with an ID that starts with "comment-":

Example2 expressions
let commentTag = TagOpen "a" [("id", "comment-45678")]tagOpenAttrNameLit "a" "id" (\idValue -> "comment-" `Data.List.isPrefixOf` idValue) commentTagTrue
valuetagOpenNameLit :: Eq str => str -> Tag str -> Bool
#

Check if the 'Tag str' is TagOpen and matches the given name

Examples

Matching an <a> tag:

Example1 expression
tagOpenNameLit "a" (TagOpen "a" [])True
Example1 expression
tagOpenNameLit "a" (TagOpen "div" [])False
valuetagCloseNameLit :: Eq str => str -> Tag str -> Bool
#

Check if the 'Tag str' is TagClose and matches the given name

Examples

Matching a closing </a> tag:

Example1 expression
tagCloseNameLit "a" (TagClose "a")True
Example1 expression
tagCloseNameLit "a" (TagClose "div")False

Matching attributes

7 declarations