{-# LANGUAGE DeriveDataTypeable #-}
module Text.HTML.TagSoup.Options where
import Data.Typeable
import Text.HTML.TagSoup.Type
import Text.HTML.TagSoup.Entity
import Text.StringLike
data ParseOptions str = ParseOptions
{forall str. ParseOptions str -> Bool
optTagPosition :: Bool
,forall str. ParseOptions str -> Bool
optTagWarning :: Bool
,forall str. ParseOptions str -> (str, Bool) -> [Tag str]
optEntityData :: (str,Bool) -> [Tag str]
,forall str. ParseOptions str -> (str, Bool) -> (str, [Tag str])
optEntityAttrib :: (str,Bool) -> (str,[Tag str])
,forall str. ParseOptions str -> Bool
optTagTextMerge :: Bool
}
deriving Typeable
parseOptionsEntities :: StringLike str => (str -> Maybe str) -> ParseOptions str
parseOptionsEntities :: forall str.
StringLike str =>
(str -> Maybe str) -> ParseOptions str
parseOptionsEntities str -> Maybe str
lookupEntity = forall str.
Bool
-> Bool
-> ((str, Bool) -> [Tag str])
-> ((str, Bool) -> (str, [Tag str]))
-> Bool
-> ParseOptions str
ParseOptions Bool
False Bool
False (str, Bool) -> [Tag str]
entityData (str, Bool) -> (str, [Tag str])
entityAttrib Bool
True
where
entityData :: (str, Bool) -> [Tag str]
entityData (str, Bool)
x = forall str. str -> Tag str
TagText str
a forall a. a -> [a] -> [a]
: [Tag str]
b
where (str
a,[Tag str]
b) = (str, Bool) -> (str, [Tag str])
entityAttrib (str, Bool)
x
entityAttrib :: (str, Bool) -> (str, [Tag str])
entityAttrib ~(str
x,Bool
b) =
let x' :: str
x' = str
x forall a. StringLike a => a -> a -> a
`append` forall a. IsString a => String -> a
fromString [Char
';'|Bool
b]
in case str -> Maybe str
lookupEntity str
x' of
Just str
y -> (str
y, [])
Maybe str
Nothing -> (forall a. StringLike a => Char -> a
fromChar Char
'&' forall a. StringLike a => a -> a -> a
`append` str
x'
,[forall str. str -> Tag str
TagWarning forall a b. (a -> b) -> a -> b
$ forall a. IsString a => String -> a
fromString String
"Unknown entity: " forall a. StringLike a => a -> a -> a
`append` str
x])
parseOptions :: StringLike str => ParseOptions str
parseOptions :: forall str. StringLike str => ParseOptions str
parseOptions = forall str.
StringLike str =>
(str -> Maybe str) -> ParseOptions str
parseOptionsEntities forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. IsString a => String -> a
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe String
lookupEntity forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. StringLike a => a -> String
toString
parseOptionsFast :: StringLike str => ParseOptions str
parseOptionsFast :: forall str. StringLike str => ParseOptions str
parseOptionsFast = forall str. StringLike str => ParseOptions str
parseOptions{optTagTextMerge :: Bool
optTagTextMerge=Bool
False}
fmapParseOptions :: (StringLike from, StringLike to) => ParseOptions from -> ParseOptions to
fmapParseOptions :: forall from to.
(StringLike from, StringLike to) =>
ParseOptions from -> ParseOptions to
fmapParseOptions (ParseOptions Bool
a Bool
b (from, Bool) -> [Tag from]
c (from, Bool) -> (from, [Tag from])
d Bool
e) = forall str.
Bool
-> Bool
-> ((str, Bool) -> [Tag str])
-> ((str, Bool) -> (str, [Tag str]))
-> Bool
-> ParseOptions str
ParseOptions Bool
a Bool
b forall {b} {a}.
(StringLike b, StringLike a) =>
(a, Bool) -> [Tag b]
c2 forall {a} {b} {a}.
(StringLike a, StringLike b, StringLike a) =>
(a, Bool) -> (a, [Tag b])
d2 Bool
e
where
c2 :: (a, Bool) -> [Tag b]
c2 ~(a
x,Bool
y) = forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (StringLike a, StringLike b) => a -> b
castString) forall a b. (a -> b) -> a -> b
$ (from, Bool) -> [Tag from]
c (forall a b. (StringLike a, StringLike b) => a -> b
castString a
x, Bool
y)
d2 :: (a, Bool) -> (a, [Tag b])
d2 ~(a
x,Bool
y) = (forall a b. (StringLike a, StringLike b) => a -> b
castString from
r, forall a b. (a -> b) -> [a] -> [b]
map (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (StringLike a, StringLike b) => a -> b
castString) [Tag from]
s)
where (from
r,[Tag from]
s) = (from, Bool) -> (from, [Tag from])
d (forall a b. (StringLike a, StringLike b) => a -> b
castString a
x, Bool
y)