Safe Haskell | None |
---|---|
Language | Haskell98 |
this module provides a QuasiQuoter that supports the HSX syntax.
- - Module : Language.Haskell.HSX.Tranform
- - Copyright : (c) Niklas Broberg 2004-2012
- - License : BSD-style (see the file LICENSE.txt)
- -
- - Maintainer : Niklas Broberg, niklas.broberg@gmail.com
- - Stability : experimental
- - Portability : portable
- -
You will need to enable the QuasiQuotes extension for it to work, which you can do by adding this to the top of your file:
{-# LANGUAGE QuasiQuotes #-}
Here is a simple example that generates an HTML fragment:
import Data.Char (toUpper) import HSX.QQ (hsx) import HSX.XMLGenerator html :: (XMLGenerator m) => XMLGenT m (XMLType m) html = [hsx| <p><% map toUpper "hello, world!" %></p> |]
The syntax used by the hsx QuasiQuoter is the same as what is used by
trhsx
. It is mostly normal XML syntax which a few key differences:
- strings inside tags and attributes are automatically escaped -- you do not need to do <, etc.
- The % syntax is used to embed the result of evaluating a Haskell expression into the XML
Values are embedde using the EmbedAsChild
and EmbedAsAttr
classes. Additional instances can be added to support application
specific types.
- hsx :: QuasiQuoter
Documentation
hsx :: QuasiQuoter Source
QuasiQuoter which can be used to parse HSX syntax