module Text.Seonbi.Html.Wrapper
( isWrappedBy
, isWrappedBy'
, wrap
) where
import Text.Seonbi.Html
import Text.Seonbi.Html.TagStack
wrap :: HtmlTagStack -> HtmlTag -> HtmlRawAttrs -> [HtmlEntity] -> [HtmlEntity]
wrap :: HtmlTagStack
-> HtmlTag -> HtmlRawAttrs -> [HtmlEntity] -> [HtmlEntity]
wrap HtmlTagStack
baseStack HtmlTag
tag' HtmlRawAttrs
attributes [HtmlEntity]
entities = (:)
(HtmlTagStack -> HtmlTag -> HtmlRawAttrs -> HtmlEntity
HtmlStartTag HtmlTagStack
baseStack HtmlTag
tag' HtmlRawAttrs
attributes)
[ HtmlEntity
e { tagStack :: HtmlTagStack
tagStack = HtmlTagStack -> HtmlTagStack
rebase' (HtmlEntity -> HtmlTagStack
tagStack HtmlEntity
e) }
| HtmlEntity
e <- [HtmlEntity]
entities
] forall a. [a] -> [a] -> [a]
++ [HtmlTagStack -> HtmlTag -> HtmlEntity
HtmlEndTag HtmlTagStack
baseStack HtmlTag
tag']
where
newBaseStack :: HtmlTagStack
newBaseStack :: HtmlTagStack
newBaseStack = HtmlTag -> HtmlTagStack -> HtmlTagStack
push HtmlTag
tag' HtmlTagStack
baseStack
rebase' :: HtmlTagStack -> HtmlTagStack
rebase' :: HtmlTagStack -> HtmlTagStack
rebase' = HtmlTagStack -> HtmlTagStack -> HtmlTagStack -> HtmlTagStack
rebase HtmlTagStack
baseStack HtmlTagStack
newBaseStack
isWrappedBy :: [HtmlEntity] -> HtmlTag -> Bool
isWrappedBy :: [HtmlEntity] -> HtmlTag -> Bool
isWrappedBy [HtmlEntity]
entities HtmlTag
tag' =
[HtmlEntity] -> HtmlTag -> Maybe HtmlRawAttrs -> Bool
isWrappedBy' [HtmlEntity]
entities HtmlTag
tag' forall a. Maybe a
Nothing
isWrappedBy' :: [HtmlEntity] -> HtmlTag -> Maybe HtmlRawAttrs -> Bool
isWrappedBy' :: [HtmlEntity] -> HtmlTag -> Maybe HtmlRawAttrs -> Bool
isWrappedBy' entities :: [HtmlEntity]
entities@(HtmlStartTag HtmlTagStack
s HtmlTag
t HtmlRawAttrs
a : [HtmlEntity]
_) HtmlTag
tag' Maybe HtmlRawAttrs
attributes =
case forall a. [a] -> a
Prelude.last [HtmlEntity]
entities of
HtmlEndTag HtmlTagStack
s' HtmlTag
t' ->
HtmlTag
t forall a. Eq a => a -> a -> Bool
== HtmlTag
tag' Bool -> Bool -> Bool
&& HtmlTag
t' forall a. Eq a => a -> a -> Bool
== HtmlTag
tag' Bool -> Bool -> Bool
&& HtmlTagStack
s forall a. Eq a => a -> a -> Bool
== HtmlTagStack
s' Bool -> Bool -> Bool
&& forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (forall a. Eq a => a -> a -> Bool
== HtmlRawAttrs
a) Maybe HtmlRawAttrs
attributes
HtmlEntity
_ ->
Bool
False
isWrappedBy' [HtmlEntity]
_ HtmlTag
_ Maybe HtmlRawAttrs
_ = Bool
False