cohost/DialogueTree.hs
2023-07-09 02:34:35 -04:00

30 lines
631 B
Haskell

module DialogueTree where
import Text.Blaze.Html.Renderer.String
import Text.Blaze.Html5
data DTree
= T Html
| O Html [(Html, DTree)]
ht :: (ToMarkup a) => a -> Html
ht = preEscapedToHtml
normalizeOption :: (Html, DTree) -> Html
normalizeOption (h, t) =
details . ht $
[summary h, normalize t]
normalize :: DTree -> Html
normalize (T s) = s
normalize (O response things) =
details . ht $
summary response
: (normalizeOption <$> things)
render :: DTree -> String
render = renderHtml . normalize
put :: DTree -> IO ()
put = putStrLn . render