{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-|
Module:      TextShow.Text.XHtml
Copyright:   (C) 2014-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

'TextShow' instances for data types in the @xhtml@ library.

/Since: 2/
-}
module TextShow.Text.XHtml () where

import Prelude ()
import Prelude.Compat

import Text.XHtml.Frameset (Html, HtmlAttr, HotLink,
                            htmlAttrPair, renderHtmlFragment)
import Text.XHtml.Table (HtmlTable)

import TextShow (TextShow(..), FromStringShow(..), fromString, singleton)
import TextShow.TH (deriveTextShow)

-- | /Since: 2/
instance TextShow Html where
    showb :: Html -> Builder
showb = String -> Builder
fromString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall html. HTML html => html -> String
renderHtmlFragment
    {-# INLINE showb #-}

    showbList :: [Html] -> Builder
showbList = forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. TextShow a => a -> Builder
showb
    {-# INLINE showbList #-}

-- | /Since: 2/
instance TextShow HtmlAttr where
    showb :: HtmlAttr -> Builder
showb HtmlAttr
ha = case HtmlAttr -> (String, String)
htmlAttrPair HtmlAttr
ha of
       (String
str, String
val) -> String -> Builder
fromString String
str forall a. Semigroup a => a -> a -> a
<> Char -> Builder
singleton Char
'=' forall a. Semigroup a => a -> a -> a
<> forall a. TextShow a => a -> Builder
showb String
val
    {-# INLINE showb #-}

-- | /Since: 2/
$(deriveTextShow ''HotLink)

-- | /Since: 2/
instance TextShow HtmlTable where
    showb :: HtmlTable -> Builder
showb = forall a. TextShow a => a -> Builder
showb forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> FromStringShow a
FromStringShow
    {-# INLINE showb #-}