{-# LANGUAGE NamedFieldPuns #-}
module Text.Seonbi.Html.Preservation
    ( isPreservedEntity
    , isPreservedTag
    , isPreservedTagStack
    ) where

import Prelude hiding (any)

import Text.Seonbi.Html.Entity
import Text.Seonbi.Html.Tag
import Text.Seonbi.Html.TagStack

-- | 'True' if the given tag should be preserved from transformation.
isPreservedTag :: HtmlTag -> Bool
isPreservedTag :: HtmlTag -> Bool
isPreservedTag HtmlTag
tag' =
    case HtmlTag
tag' of
        HtmlTag
Code -> Bool
True
        HtmlTag
Kbd -> Bool
True
        HtmlTag
Pre -> Bool
True
        HtmlTag
TextArea -> Bool
True
        HtmlTag
_ ->
            case HtmlTag -> HtmlTagKind
htmlTagKind HtmlTag
tag' of
                HtmlTagKind
Normal -> Bool
False
                HtmlTagKind
EscapableRawText -> Bool
False
                HtmlTagKind
_ -> Bool
True

-- | 'True' if the given tag stack should be preserved from transformation.
isPreservedTagStack :: HtmlTagStack -> Bool
isPreservedTagStack :: HtmlTagStack -> Bool
isPreservedTagStack = (HtmlTag -> Bool) -> HtmlTagStack -> Bool
any HtmlTag -> Bool
isPreservedTag

-- | 'True' if the given HTML entity should be preserved from transformation.
isPreservedEntity :: HtmlEntity -> Bool
isPreservedEntity :: HtmlEntity -> Bool
isPreservedEntity HtmlComment {} =
    Bool
True
isPreservedEntity HtmlStartTag { HtmlTagStack
tagStack :: HtmlEntity -> HtmlTagStack
tagStack :: HtmlTagStack
tagStack, HtmlTag
tag :: HtmlEntity -> HtmlTag
tag :: HtmlTag
tag } =
    HtmlTag -> Bool
isPreservedTag HtmlTag
tag Bool -> Bool -> Bool
|| HtmlTagStack -> Bool
isPreservedTagStack HtmlTagStack
tagStack
isPreservedEntity HtmlEndTag { HtmlTagStack
tagStack :: HtmlTagStack
tagStack :: HtmlEntity -> HtmlTagStack
tagStack, HtmlTag
tag :: HtmlTag
tag :: HtmlEntity -> HtmlTag
tag } =
    HtmlTag -> Bool
isPreservedTag HtmlTag
tag Bool -> Bool -> Bool
|| HtmlTagStack -> Bool
isPreservedTagStack HtmlTagStack
tagStack
isPreservedEntity HtmlEntity
entity =
    HtmlTagStack -> Bool
isPreservedTagStack forall a b. (a -> b) -> a -> b
$ HtmlEntity -> HtmlTagStack
tagStack HtmlEntity
entity