Text.Blaze
Contents
Description
Core exposed functions.
- data Html a
- data Tag
- data Attribute
- data AttributeValue
- dataAttribute :: Tag -> AttributeValue -> Attribute
- text :: Text -> Html a
- preEscapedText :: Text -> Html a
- string :: String -> Html a
- preEscapedString :: String -> Html a
- showHtml :: Show a => a -> Html b
- preEscapedShowHtml :: Show a => a -> Html b
- unsafeByteString :: ByteString -> Html a
- textTag :: Text -> Tag
- stringTag :: String -> Tag
- textValue :: Text -> AttributeValue
- preEscapedTextValue :: Text -> AttributeValue
- stringValue :: String -> AttributeValue
- preEscapedStringValue :: String -> AttributeValue
- (!) :: Attributable h => h -> Attribute -> h
- renderHtml :: Html a -> ByteString
Important types.
The core HTML datatype.
Type for an HTML tag. This can be seen as an internal string type used by BlazeHtml.
Creating attributes.
Arguments
:: Tag | Name of the attribute. |
-> AttributeValue | Value for the attribute. |
-> Attribute | Resulting HTML attribute. |
From HTML 5 onwards, the user is able to specify custom data attributes.
An example:
<p data-foo="bar">Hello.</p>
We support this in BlazeHtml using this funcion. The above fragment could be described using BlazeHtml with:
p ! dataAttribute "foo" "bar" $ "Hello."
Converting values to HTML.
Render text. Functions like these can be used to supply content in HTML.
Create an HTML snippet from a String
.
preEscapedString :: String -> Html aSource
Create an HTML snippet from a String
without escaping
Create an HTML snippet from a datatype that instantiates Show
.
Create an HTML snippet from a datatype that instantiates Show
. This
function will not do any HTML entity escaping.
Inserting literal ByteString's.
Arguments
:: ByteString | Value to insert. |
-> Html a | Resulting HTML fragment. |
Insert a ByteString
. This is an unsafe operation:
- The
ByteString
could have the wrong encoding. - The
ByteString
might contain illegal HTML characters (no escaping is done).
Creating tags.
Create a tag from a Text
value. A tag is a string used to denote a
certain HTML element, for example img
.
This is only useful if you want to create custom HTML combinators.
Converting values to attribute values.
Arguments
:: Text | The actual value. |
-> AttributeValue | Resulting attribute value. |
Render an attribute value from Text
.
Arguments
:: Text | Text to insert. |
-> AttributeValue |
Render an attribute value from Text
without escaping.
stringValue :: String -> AttributeValueSource
Create an attribute value from a String
.
preEscapedStringValue :: String -> AttributeValueSource
Create an attribute value from a String
without escaping.
Setting attributes
(!) :: Attributable h => h -> Attribute -> hSource
Apply an attribute to an element.
Example:
img ! src "foo.png"
Result:
<img src="foo.png" />
This can be used on nested elements as well.
Example:
p ! style "float: right" $ "Hello!"
Result:
<p style="float: right">Hello!</p>
Rendering HTML.
Arguments
:: Html a | Document to render. |
-> ByteString | Resulting output. |
O(n). Render the HTML fragment to lazy ByteString
.