-- © 2001 Peter Thiemann
module Wash.HTMLMonad (module Wash.HTMLMonad,module Wash.HTMLBase) where
import Prelude hiding (div,head,map,span)
import Wash.HTMLBase
type Element = ELEMENT_
type Attributes = [Attribute]
type Attribute = ATTR_
data WithHTML m a =
  WithHTML { unWithHTML :: ELEMENT_ -> m (a, ELEMENT_) }
instance Monad m => Monad (WithHTML m) where
  return a = WithHTML (\elem -> return (a, elem))
  ma >>= f = WithHTML (\elem -> unWithHTML ma elem >>= \(a, elem') ->
                                unWithHTML (f a) elem')
lift :: Monad m => m a -> WithHTML m a
lift ma = WithHTML (\elem -> ma >>= \a -> return (a, elem))
-- empty element collection
empty :: Monad m => WithHTML m ()
empty = return ()
-- concatenation of collections
x ## y = x >>= \a -> y >> return a
--
type HTMLCons m a = WithHTML m a -> WithHTML m a
text, rawtext, formattedtext :: Monad m => String -> WithHTML m ()
text s = WithHTML (\elem -> return ((), add_ elem (cdata_ [] s)))
rawtext s = WithHTML (\elem -> return ((), add_ elem (cdata_ [CDATA_ENCODED] s)))
formattedtext s = WithHTML (\elem -> return ((), add_ elem (cdata_ [CDATA_FORMATTED] s)))
attr :: Monad m => String -> String -> WithHTML m ()
attr a v = WithHTML (\ elem -> return ((), add_attr_ elem (attr_ a v)))
addMaker subelem ma =
  WithHTML (\elem -> unWithHTML ma subelem >>= \(a, subelem') ->
                     return (a, add_ elem subelem'))
build_document :: Monad m => WithHTML m a -> m ELEMENT_
build_document ma = unWithHTML ma
  (doctype_ ["HTML", "PUBLIC", "\"-//W3C//DTD XHTML 1.0 Strict//EN\"", "\"DTD/xhtml1-strict.dtd\""] [])
  >>= \ (a, elem) -> return elem
-- end fixed prologue
a :: Monad m => HTMLCons m a
a = addMaker $ element_ "a" [] []
abbr :: Monad m => HTMLCons m a
abbr = addMaker $ element_ "abbr" [] []
acronym :: Monad m => HTMLCons m a
acronym = addMaker $ element_ "acronym" [] []
address :: Monad m => HTMLCons m a
address = addMaker $ element_ "address" [] []
applet :: Monad m => HTMLCons m a
applet = addMaker $ element_ "applet" [] []
area :: Monad m => HTMLCons m ()
area = addMaker $ empty_ "area" []
b :: Monad m => HTMLCons m a
b = addMaker $ element_ "b" [] []
base :: Monad m => HTMLCons m ()
base = addMaker $ empty_ "base" []
basefont :: Monad m => HTMLCons m ()
basefont = addMaker $ empty_ "basefont" []
bdo :: Monad m => HTMLCons m a
bdo = addMaker $ element_ "bdo" [] []
big :: Monad m => HTMLCons m a
big = addMaker $ element_ "big" [] []
blockquote :: Monad m => HTMLCons m a
blockquote = addMaker $ element_ "blockquote" [] []
body :: Monad m => HTMLCons m a
body = addMaker $ element_ "body" [] []
br :: Monad m => HTMLCons m ()
br = addMaker $ empty_ "br" []
button :: Monad m => HTMLCons m a
button = addMaker $ element_ "button" [] []
caption :: Monad m => HTMLCons m a
caption = addMaker $ element_ "caption" [] []
center :: Monad m => HTMLCons m a
center = addMaker $ element_ "center" [] []
cite :: Monad m => HTMLCons m a
cite = addMaker $ element_ "cite" [] []
code :: Monad m => HTMLCons m a
code = addMaker $ element_ "code" [] []
col :: Monad m => HTMLCons m ()
col = addMaker $ empty_ "col" []
colgroup :: Monad m => HTMLCons m a
colgroup = addMaker $ element_ "colgroup" [] []
dd :: Monad m => HTMLCons m a
dd = addMaker $ element_ "dd" [] []
del :: Monad m => HTMLCons m a
del = addMaker $ element_ "del" [] []
dfn :: Monad m => HTMLCons m a
dfn = addMaker $ element_ "dfn" [] []
dir :: Monad m => HTMLCons m a
dir = addMaker $ element_ "dir" [] []
div :: Monad m => HTMLCons m a
div = addMaker $ element_ "div" [] []
dl :: Monad m => HTMLCons m a
dl = addMaker $ element_ "dl" [] []
dt :: Monad m => HTMLCons m a
dt = addMaker $ element_ "dt" [] []
em :: Monad m => HTMLCons m a
em = addMaker $ element_ "em" [] []
fieldset :: Monad m => HTMLCons m a
fieldset = addMaker $ element_ "fieldset" [] []
font :: Monad m => HTMLCons m a
font = addMaker $ element_ "font" [] []
form :: Monad m => HTMLCons m a
form = addMaker $ element_ "form" [] []
h1 :: Monad m => HTMLCons m a
h1 = addMaker $ element_ "h1" [] []
h2 :: Monad m => HTMLCons m a
h2 = addMaker $ element_ "h2" [] []
h3 :: Monad m => HTMLCons m a
h3 = addMaker $ element_ "h3" [] []
h4 :: Monad m => HTMLCons m a
h4 = addMaker $ element_ "h4" [] []
h5 :: Monad m => HTMLCons m a
h5 = addMaker $ element_ "h5" [] []
h6 :: Monad m => HTMLCons m a
h6 = addMaker $ element_ "h6" [] []
head :: Monad m => HTMLCons m a
head = addMaker $ element_ "head" [] []
hr :: Monad m => HTMLCons m ()
hr = addMaker $ empty_ "hr" []
html :: Monad m => HTMLCons m a
html = addMaker $ element_ "html" [] []
i :: Monad m => HTMLCons m a
i = addMaker $ element_ "i" [] []
iframe :: Monad m => HTMLCons m a
iframe = addMaker $ element_ "iframe" [] []
img :: Monad m => HTMLCons m ()
img = addMaker $ empty_ "img" []
input :: Monad m => HTMLCons m ()
input = addMaker $ empty_ "input" []
ins :: Monad m => HTMLCons m a
ins = addMaker $ element_ "ins" [] []
isindex :: Monad m => HTMLCons m ()
isindex = addMaker $ empty_ "isindex" []
kbd :: Monad m => HTMLCons m a
kbd = addMaker $ element_ "kbd" [] []
label :: Monad m => HTMLCons m a
label = addMaker $ element_ "label" [] []
legend :: Monad m => HTMLCons m a
legend = addMaker $ element_ "legend" [] []
li :: Monad m => HTMLCons m a
li = addMaker $ element_ "li" [] []
link :: Monad m => HTMLCons m ()
link = addMaker $ empty_ "link" []
map :: Monad m => HTMLCons m a
map = addMaker $ element_ "map" [] []
menu :: Monad m => HTMLCons m a
menu = addMaker $ element_ "menu" [] []
meta :: Monad m => HTMLCons m ()
meta = addMaker $ empty_ "meta" []
noframes :: Monad m => HTMLCons m a
noframes = addMaker $ element_ "noframes" [] []
noscript :: Monad m => HTMLCons m a
noscript = addMaker $ element_ "noscript" [] []
object :: Monad m => HTMLCons m a
object = addMaker $ element_ "object" [] []
ol :: Monad m => HTMLCons m a
ol = addMaker $ element_ "ol" [] []
optgroup :: Monad m => HTMLCons m a
optgroup = addMaker $ element_ "optgroup" [] []
option :: Monad m => HTMLCons m a
option = addMaker $ element_ "option" [] []
p :: Monad m => HTMLCons m a
p = addMaker $ element_ "p" [] []
param :: Monad m => HTMLCons m ()
param = addMaker $ empty_ "param" []
pre :: Monad m => HTMLCons m a
pre = addMaker $ element_ "pre" [] []
q :: Monad m => HTMLCons m a
q = addMaker $ element_ "q" [] []
s :: Monad m => HTMLCons m a
s = addMaker $ element_ "s" [] []
samp :: Monad m => HTMLCons m a
samp = addMaker $ element_ "samp" [] []
script :: Monad m => HTMLCons m a
script = addMaker $ element_ "script" [] []
select :: Monad m => HTMLCons m a
select = addMaker $ element_ "select" [] []
small :: Monad m => HTMLCons m a
small = addMaker $ element_ "small" [] []
span :: Monad m => HTMLCons m a
span = addMaker $ element_ "span" [] []
strike :: Monad m => HTMLCons m a
strike = addMaker $ element_ "strike" [] []
strong :: Monad m => HTMLCons m a
strong = addMaker $ element_ "strong" [] []
style :: Monad m => HTMLCons m a
style = addMaker $ element_ "style" [] []
sub :: Monad m => HTMLCons m a
sub = addMaker $ element_ "sub" [] []
sup :: Monad m => HTMLCons m a
sup = addMaker $ element_ "sup" [] []
table :: Monad m => HTMLCons m a
table = addMaker $ element_ "table" [] []
tbody :: Monad m => HTMLCons m a
tbody = addMaker $ element_ "tbody" [] []
td :: Monad m => HTMLCons m a
td = addMaker $ element_ "td" [] []
textarea :: Monad m => HTMLCons m a
textarea = addMaker $ element_ "textarea" [] []
tfoot :: Monad m => HTMLCons m a
tfoot = addMaker $ element_ "tfoot" [] []
th :: Monad m => HTMLCons m a
th = addMaker $ element_ "th" [] []
thead :: Monad m => HTMLCons m a
thead = addMaker $ element_ "thead" [] []
title :: Monad m => HTMLCons m a
title = addMaker $ element_ "title" [] []
tr :: Monad m => HTMLCons m a
tr = addMaker $ element_ "tr" [] []
tt :: Monad m => HTMLCons m a
tt = addMaker $ element_ "tt" [] []
u :: Monad m => HTMLCons m a
u = addMaker $ element_ "u" [] []
ul :: Monad m => HTMLCons m a
ul = addMaker $ element_ "ul" [] []
var :: Monad m => HTMLCons m a
var = addMaker $ element_ "var" [] []
