BlazeMarkup is a markup combinator library. It provides a way to embed
markup languages like HTML and SVG in Haskell in an efficient and
convenient way, with a light-weight syntax.
To use the library, one needs to import a set of combinators. For
example, you can use HTML 4 Strict from BlazeHtml package.
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (head, id, div)
import Text.Blaze.Html4.Strict hiding (map)
import Text.Blaze.Html4.Strict.Attributes hiding (title)
To render the page later on, you need a so called Renderer. The
recommended renderer is an UTF-8 renderer which produces a lazy
bytestring.
import Text.Blaze.Renderer.Utf8 (renderMarkup)
Now, you can describe pages using the imported combinators.
page1 :: Markup
page1 = html $ do
head $ do
title "Introduction page."
link ! rel "stylesheet" ! type_ "text/css" ! href "screen.css"
body $ do
div ! id "header" $ "Syntax"
p "This is an example of BlazeMarkup syntax."
ul $ mapM_ (li . toMarkup . show) [1, 2, 3]
The resulting HTML can now be extracted using:
renderMarkup page1