module Text.Docs.Class (
Documentable (..)
, emptydoc
, dunlines
, DocTitled (..)
, DocLinked (..)
, DocList (..)
) where
import Data.Monoid
import qualified Text.Html as H
class Documentable a where
text :: String -> a
code :: String -> a
codeblock :: String -> a
emphasize :: a -> a
dappend :: a -> a -> a
lnappend :: a -> a -> a
renderdoc :: a -> String
lnappend x y = x `dappend` text "\n" `dappend` y
emptydoc :: Documentable a => a
emptydoc = text []
dunlines :: Documentable a => [a] -> a
dunlines = foldr lnappend emptydoc
class Documentable a => DocTitled a where
title :: a -> a
subtitle :: a -> a
title = id
subtitle = title
class Documentable a => DocLinked a where
url :: String -> a
nameurl :: String -> String -> a
url = text
nameurl _ y = url y
class Documentable a => DocList a where
ulist :: [a] -> a
elist :: [a] -> a
ulist = dunlines . map (dappend $ text "* ")
elist = dunlines . zipWith (\n x -> (text $ show n) `dappend` text ". " `dappend` x ) [1..]
instance Documentable H.Html where
text = H.stringToHtml
code = H.thecode . text
codeblock = H.pre . text
emphasize = H.emphasize
dappend = (H.+++)
renderdoc = H.renderHtml
instance DocTitled H.Html where
title = H.h1
subtitle = H.h2
instance DocLinked H.Html where
url x = (H.![H.href x]) . H.anchor . text $ x
nameurl x y = (H.![H.href y]) . H.anchor . text $ x
instance DocList H.Html where
ulist = H.ulist . H.concatHtml . map H.li
elist = H.olist . H.concatHtml . map H.li