--import Text.CHXHtml.XHtml1_strict import XHtml1_strict -- import Text.CHXHtml.XHtml1_transitional -- import Text.CHXHtml.Strict4_01 -- tr not allowed under table, will not compile as is -- import Text.CHXHtml.Loose4_01 -- tr not allowed under table, will not compile as is -- CHXHtml demo.hs -- -- Paul Talaga -- July 20, 2011 -- -- Construct a static Hello World XHTML1 Strict compliant page -- rendered as a String via render. -- -- Import the transitional library for XHTML Transitional compliance. -- Both HTML 4.01 Stict and Loose do not allow a tr to be a child of table, insert tbody -- for correct markup. -- -- 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 tag can not be under , but inside a
. -- 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 [_img], _div [_a [_img]], _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]) ] -- childErrors will return a list of tag ordering errors at runtime. -- Sorry, for usability we use lists for children and thus can't catch those errors at compile time. errors = childErrors helloWorld