CHXHtml-0.1.1: demo.hs
import Text.CHXHtml.XHtml1_strict
-- CHXHtml demo.hs
--
-- Paul Talaga -- June 5, 2010
--
-- Construct a static Hello World XHTML1 Strict compliant page
-- rendered as a String via render.
--
-- Opionally produce a multiplication table
main :: IO ()
main = putStrLn (render helloWorld)
--main = putStrLn (render (helloWorldTable 5))
helloWorld = helloWorldTemplate []
-- Simple Hello World template page
helloWorldTemplate content =
_html [
_head [
_title [pcdata "Hello World Page"]
],
_body [_h1 [pcdata "Hello World"],
_hr,
div_ [style_att "background-color:blue;"] [pcdata "First Paragraph"],
-- The <a> tag can not be under <body>, but inside a <div>.
-- Try > htmlHelp ["html","body"] to get a list of allowed tags and attributes
-- Uncomment the following line to cause a type error.
-- _a [pcdata "Will not work!"],
_div [a_ [href_att "http://google.com"] [pcdata "Click Me!"]],
div_ [style_att "background-color:blue;"] [pcdata "Another Paragraph"],
_div [temp],
_div [_a [temp]],
_div content
]
]
-- Hello World table page with dynamic table multiplication table
-- Because children are specified as a list, we can use Haskell's built-in functions for
-- list manipulation and creation.
helloWorldTable n = helloWorldTemplate
[table_ [border_att "1"]
(map (\i->_tr
(map (\j->_td [pcdata (show (i * j))]) [1..n])
) [1..n])
]
temp = _img
temp2 = _img