cohost/DialogueTree.hs

30 lines
631 B
Haskell
Raw Permalink Normal View History

2023-07-09 02:34:35 -04:00
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