hako-0.2.0: A mako-like quasi-quoter template library

Safe HaskellNone

Text.Hako.Html

Description

Implements HTML-encoding for Hako. The Html type and the ToHtml typeclass together take care of html-encoding appropriately and automatically inside Hako templates.

Synopsis

Documentation

htmlEncode :: String -> HtmlSource

Basic HTML-encoding: converts all special HTML characters into the corresponding entities.

data Html Source

A piece of HTML source. Use fromHtml to get the HTML source back out.

Constructors

Html String 

Instances

Eq Html 
Show Html 
ToHtml Html

Html itself is also a member of ToHtml; converting from Html to Html is an identity.

class ToHtml a whereSource

All expressions interpolated into Hako templates using {} syntax must satisfy ToHtml. Any member of Show automatically has a default implementation through show; additionally, suitable implementations are provided for String (skipping the quoting and escaping which show would otherwise introduce), as well as Lists, Maybes and Eithers of ToHtmls.

Methods

toHtml :: a -> HtmlSource

Instances

Show a => ToHtml a

All other types in Show default to HTML-encoding their show representation.

ToHtml Html

Html itself is also a member of ToHtml; converting from Html to Html is an identity.

ToHtml [Char]

Strings have their own instance of ToHtml, which performs HTML-encoding but skips the call to show which would otherwise introduce undesirable quotes and escaping.

ToHtml a => ToHtml [a]

Lists are automatically folded using straightforward concatenation.

ToHtml a => ToHtml (Maybe a)

Implement an instance for Maybe, so that Nothing is leniently converted to an empty string, and Justs are unpacked.

(ToHtml a, ToHtml b) => ToHtml (Either a b)

Either should work also, as long as both branches are ToHtml themselves.

fromHtml :: Html -> StringSource

Get HTML source as String

(<++>) :: Html -> Html -> HtmlSource

Concatenate two Htmls together. The Html equivalent to list concatenation (++)