    {-# LANGUAGE OverloadedStrings #-}
    -- | Prender CSS with renderNestedBlocks
    module Text.CSS.Render
        ( renderNestedBlocks
        , renderBlocks
        , renderBlock
        , renderAttrs
        , renderAttr
        ) where

    import Data.Text (Text)
    import Data.Text.Lazy.Builder (Builder, fromText, singleton)
    import Data.Monoid (mempty, mconcat)
    import Data.Semigroup ((<>))
    import Text.CSS.Parse

    renderAttr :: (Text, Text) -> Builder
    renderAttr :: (Text, Text) -> Builder
    renderAttr (Text
    k, Text
    v) = Text -> Builder
    fromText Text
    k Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Char -> Builder
    singleton Char
    ':' Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Text -> Builder
    fromText Text
    v

    renderAttrs :: [(Text, Text)] -> Builder
    renderAttrs :: [(Text, Text)] -> Builder
    renderAttrs [] = Builder
    forall a. Monoid a => a
    mempty
    renderAttrs [(Text, Text)
    x] = (Text, Text) -> Builder
    renderAttr (Text, Text)
    x
    renderAttrs ((Text, Text)
    x:[(Text, Text)]
    xs) = (Text, Text) -> Builder
    renderAttr (Text, Text)
    x Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Char -> Builder
    singleton Char
    ';' Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> [(Text, Text)] -> Builder
    renderAttrs [(Text, Text)]
    xs

    renderBlock :: (Text, [(Text, Text)]) -> Builder
    renderBlock :: (Text, [(Text, Text)]) -> Builder
    renderBlock (Text
    sel, [(Text, Text)]
    attrs) =
        Text -> Builder
    fromText Text
    sel Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Char -> Builder
    singleton Char
    '{' Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> [(Text, Text)] -> Builder
    renderAttrs [(Text, Text)]
    attrs Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Char -> Builder
    singleton Char
    '}'

    renderBlocks :: [(Text, [(Text, Text)])] -> Builder
    renderBlocks :: [(Text, [(Text, Text)])] -> Builder
    renderBlocks = [Builder] -> Builder
    forall a. Monoid a => [a] -> a
    mconcat ([Builder] -> Builder)
    -> ([(Text, [(Text, Text)])] -> [Builder])
    -> [(Text, [(Text, Text)])]
    -> Builder
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Text, [(Text, Text)]) -> Builder)
    -> [(Text, [(Text, Text)])] -> [Builder]
    forall a b. (a -> b) -> [a] -> [b]
    map (Text, [(Text, Text)]) -> Builder
    renderBlock

    renderNestedBlock :: NestedBlock -> Builder
    renderNestedBlock :: NestedBlock -> Builder
    renderNestedBlock (LeafBlock (Text, [(Text, Text)])
    b) = (Text, [(Text, Text)]) -> Builder
    renderBlock (Text, [(Text, Text)])
    b
    renderNestedBlock (NestedBlock Text
    t [NestedBlock]
    bs) = Text -> Builder
    fromText Text
    t
                                        Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Char -> Builder
    singleton Char
    '{'
                                        Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> [NestedBlock] -> Builder
    renderNestedBlocks [NestedBlock]
    bs
                                        Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Char -> Builder
    singleton Char
    '}'

    renderNestedBlocks :: [NestedBlock] -> Builder
    renderNestedBlocks :: [NestedBlock] -> Builder
    renderNestedBlocks = [Builder] -> Builder
    forall a. Monoid a => [a] -> a
    mconcat ([Builder] -> Builder)
    -> ([NestedBlock] -> [Builder]) -> [NestedBlock] -> Builder
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (NestedBlock -> Builder) -> [NestedBlock] -> [Builder]
    forall a b. (a -> b) -> [a] -> [b]
    map NestedBlock -> Builder
    renderNestedBlock