hsp-0.10.0: Haskell Server Pages is a library for writing dynamic server-side web pages.

Copyright | (c) Niklas Broberg Jeremy Shaw 2008-2012
License | BSD-style (see the file LICENSE.txt)
Maintainer | Niklas Broberg, niklas.broberg@gmail.com
Stability | experimental
Portability | Haskell 98
Safe Haskell | Safe-Inferred
Language | Haskell98

HSP.HTML4

Contents

- Functions
- Predefined XMLMetaData

Description

Attempt to render XHTML as well-formed HTML 4.01:

1. no short tags are used, e.g., <script></script> instead of <script />
2. the end tag is forbidden for some elements, for these we:

- render only the open tag, e.g., <br>
- throw an error if the tag contains children

1. optional end tags are always rendered

Currently no validation is performed.

Synopsis

- renderAsHTML :: XML -> Text
- htmlEscapeChars :: [(Char, Builder)]
- html4Strict :: Maybe XMLMetaData
- html4StrictFrag :: Maybe XMLMetaData

# Functions

renderAsHTML :: XML -> Text #

Pretty-prints HTML values.

Error Handling:

Some tags (such as img) can not contain children in HTML. However, there is nothing to stop the caller from passing in XML which contains an img tag with children. There are three basic ways to handle this:

1. drop the bogus children silently
2. call `error` / raise an exception
3. render the img tag with children -- even though it is invalid

Currently we are taking approach #3, since no other attempts to validate the data are made in this function. Instead, you can run the output through a full HTML validator to detect the errors.

#1 seems like a poor choice, since it makes is easy to overlook the fact that data went missing.

We could raising errors, but you have to be in the IO monad to catch them. Also, you have to use evaluate if you want to check for errors. This means you can not start sending the page until the whole page has been rendered. And you have to store the whole page in RAM at once. Similar problems occur if we return Either instead. We mostly care about catching errors and showing them in the browser during testing, so perhaps this can be configurable.

Another solution would be a compile time error if an empty-only tag contained children.

FIXME: also verify that the domain is correct

FIXME: what to do if a namespace is encountered

htmlEscapeChars :: [(Char, Builder)] #

# Predefined XMLMetaData

html4Strict :: Maybe XMLMetaData #

html4StrictFrag :: Maybe XMLMetaData #