blaze-html-0.1.2: A blazingly fast HTML combinator library.

Text.Blaze

Contents

Description

Core exposed functions.

Synopsis

Important types.

data Html a Source

The core HTML datatype.

Instances

Monad Html 
IsString (Html a) 
Monoid (Html a) 
Attributable (Html a) 
Attributable (Html a -> Html b) 

data Tag Source

Type for an HTML tag. This can be seen as an internal string type used by BlazeHtml.

Instances

data Attribute Source

Type for an attribute.

data AttributeValue Source

The type for the value part of an attribute.

Creating attributes.

dataAttributeSource

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.

textSource

Arguments

:: Text

Text to render.

-> Html a

Resulting HTML fragment.

Render text. Functions like these can be used to supply content in HTML.

preEscapedTextSource

Arguments

:: Text

Text to insert.

-> Html a 

Render text without escaping.

stringSource

Arguments

:: String

String to insert.

-> Html a

Resulting HTML fragment.

Create an HTML snippet from a String.

preEscapedString :: String -> Html aSource

Create an HTML snippet from a String without escaping

showHtmlSource

Arguments

:: Show a 
=> a

Value to insert.

-> Html b

Resulting HTML fragment.

Create an HTML snippet from a datatype that instantiates Show.

preEscapedShowHtmlSource

Arguments

:: Show a 
=> a

Value to insert.

-> Html b

Resulting HTML fragment.

Create an HTML snippet from a datatype that instantiates Show. This function will not do any HTML entity escaping.

Inserting literal ByteString's.

unsafeByteStringSource

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.

textTagSource

Arguments

:: Text

Text for the tag.

-> Tag

Resulting tag.

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.

stringTagSource

Arguments

:: String

String for the tag.

-> Tag

Resulting tag.

Create a tag from a String value. For more information, see textTag.

Converting values to attribute values.

textValueSource

Arguments

:: Text

The actual value.

-> AttributeValue

Resulting attribute value.

Render an attribute value from Text.

preEscapedTextValueSource

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.

renderHtmlSource

Arguments

:: Html a

Document to render.

-> ByteString

Resulting output.

O(n). Render the HTML fragment to lazy ByteString.