Simplification of the MarkupM datatype.
Moduleblaze-markup-0.8.3.0Haskell2010
Text.Blaze
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- 4 types
- 2 classes
- 27 values
- Packageblaze-markup-0.8.3.0
- Exports34
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceBlaze.hs
Important types.
4 declarationsType for an HTML tag. This can be seen as an internal string type used by BlazeMarkup.
Type for an attribute.
The type for the value part of an attribute.
Instances4IsString, Semigroup, Monoid, ToValue
IsString AttributeValueDefined in blaze-markup-0.8.3.0 · Text.Blaze.InternalSemigroup AttributeValueDefined in blaze-markup-0.8.3.0 · Text.Blaze.InternalMonoid AttributeValueDefined in blaze-markup-0.8.3.0 · Text.Blaze.InternalToValue AttributeValueDefined in blaze-markup-0.8.3.0 · Text.Blaze
Creating attributes.
2 declarationsdataAttribute :: TagName of the attribute.
-> AttributeValueValue for the attribute.
-> AttributeResulting 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 BlazeMarkup using this function. The above fragment could be described using BlazeMarkup with:
p ! dataAttribute "foo" "bar" $ "Hello."customAttribute :: TagName of the attribute
-> AttributeValueValue for the attribute
-> AttributeResulting HTML attribtue
Create a custom attribute. This is not specified in the HTML spec, but some JavaScript libraries rely on it.
An example:
<select dojoType="select">foo</select>Can be produced using:
select ! customAttribute "dojoType" "select" $ "foo"Converting values to Markup.
9 declarationsClass allowing us to use a single function for Markup values
Methods
toMarkup :: a -> MarkupConvert a value to Markup.
preEscapedToMarkup :: a -> MarkupConvert a value to Markup without escaping
Instances19ToMarkup, …
ToMarkup MarkupDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup IntegerDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup NaturalDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup StringDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup Int32Defined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup Int64Defined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup Word32Defined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup Word64Defined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup BoolDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup CharDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup DoubleDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup FloatDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup IntDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup WordDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup TextDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup BuilderDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup TextDefined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup (NonEmpty Char)Defined in blaze-markup-0.8.3.0 · Text.BlazeToMarkup [Markup]Defined in blaze-markup-0.8.3.0 · Text.Blaze
Render text. Functions like these can be used to supply content in HTML.
Render text without escaping.
A variant of preEscapedText for lazy Text
Create an HTML snippet from a String.
Create an HTML snippet from a String without escaping
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).
Insert a lazy ByteString. See unsafeByteString for reasons why this is an unsafe operation.
Comments
5 declarationsCreate a comment from a Text value.
The text should not contain "--".
This is not checked by the library.
Create a comment from a Text value.
The text should not contain "--".
This is not checked by the library.
Create a comment from a String value.
The text should not contain "--".
This is not checked by the library.
Create a comment from a ByteString value.
The text should not contain "--".
This is not checked by the library.
Create a comment from a ByteString value.
The text should not contain "--".
This is not checked by the library.
Creating tags.
2 declarationsConverting values to attribute values.
9 declarationsClass allowing us to use a single function for attribute values
Methods
toValue :: a -> AttributeValueConvert a value to an attribute value
preEscapedToValue :: a -> AttributeValueConvert a value to an attribute value without escaping
Instances17ToValue, …
ToValue AttributeValueDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue IntegerDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue StringDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue Int32Defined in blaze-markup-0.8.3.0 · Text.BlazeToValue Int64Defined in blaze-markup-0.8.3.0 · Text.BlazeToValue Word32Defined in blaze-markup-0.8.3.0 · Text.BlazeToValue Word64Defined in blaze-markup-0.8.3.0 · Text.BlazeToValue BoolDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue CharDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue DoubleDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue FloatDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue IntDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue WordDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue TextDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue BuilderDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue TextDefined in blaze-markup-0.8.3.0 · Text.BlazeToValue (NonEmpty Char)Defined in blaze-markup-0.8.3.0 · Text.Blaze
Render an attribute value from Text.
Render an attribute value from Text without escaping.
A variant of preEscapedTextValue for lazy Text
Create an attribute value from a String.
Create an attribute value from a String without escaping.
Create an attribute value from a ByteString. See unsafeByteString for reasons why this might not be a good idea.
unsafeLazyByteStringValue :: ByteStringByteString value
-> AttributeValueResulting attribute value
Create an attribute value from a lazy ByteString. See unsafeByteString for reasons why this might not be a good idea.
Setting attributes
2 declarationsApply 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>Shorthand for setting an attribute depending on a conditional.
Example:
p !? (isBig, A.class "big") $ "Hello"Gives the same result as:
(if isBig then p ! A.class "big" else p) "Hello"Modifying Markup trees
1 declarationTake only the text content of an HTML tree.
contents $ do
p ! $ "Hello "
p ! $ "Word!"Result:
Hello World!