{-# LANGUAGE OverloadedStrings, DefaultSignatures, TypeSynonymInstances, FlexibleInstances #-} module Inliterate.Import where import Data.Time import qualified Data.Text as T import qualified Data.Text.Lazy.IO as TL import Lucid import Lucid.Bootstrap3 import Lucid.PreEscaped import Control.Monad (unless) import System.Environment import Data.List (intercalate) import Graphics.Plotly import Graphics.Plotly.Lucid () data CodeType = Top | Eval | Do | Hide | Fake | Twocol | Noq deriving (Show, Eq, Read, Ord) class AskInliterate a where askInliterate :: String -> [CodeType] -> a -> IO () default askInliterate :: Show a => String -> [CodeType] -> a -> IO () askInliterate = answerWith show answerWith :: (a -> String) -> String -> [CodeType] -> a -> IO () answerWith f t cts x = do putStr "
"
putStrLn $ concat [t, " => \n", f x]
putStrLn "
"
instance AskInliterate Int
instance AskInliterate Double
instance AskInliterate Float
instance AskInliterate UTCTime
instance AskInliterate String where
askInliterate = answerWith id
instance AskInliterate T.Text where
askInliterate = answerWith T.unpack
instance (Show a, Show b) => AskInliterate (a,b)
instance AskInliterate (Html ()) where
askInliterate q cts html
| Twocol `elem` cts = do
putStrLn ""
putStrLn $ q
putStrLn "
"
putStrLn "