BlazeHtml 0.4

Posted in: haskell.

I’ve just uploaded BlazeHtml 0.4 to Hackage. There’s some new things in there, so I thought it would be a good idea to summarize it here.

Text renderer

A Text renderer was added in the new Text.Blaze.Renderer.Text module. The interface should look quite familiar to everyone who looked at BlazeHtml before:

renderHtml :: Html -> Text

The produced Text is lazy, built by the Text builder that was recently added. It isn’t as fast as the UTF8 ByteString renderer, but there is still room for some improvements here.

Removal of showHtml methods

The showHtml functions were removed – this breaks backwards compatibility, but:

The ToHtml/ToValue typeclasses

We’ve added two handy typeclasses at the top of BlazeHtml, in the Text.Blaze module.

class ToHtml a where
    toHtml :: a -> Html
class ToValue a where
    toValue :: a -> AttributeValue

They have all the instances one would expect: the different string types such as Text and lazy Text, and some other common types such as numerical values (Int, Float …).

This means that in most cases, showHtml can also be replaced by toHtml. The advantage of using these functions is that they provide a more unified interface to the web developer.

Hexpat renderer

I also added a Hexpat renderer some time ago. You can read more about that here. Like the other renderers, it provides a simple renderHtml -> Forest function (where Forest is a forest of Hexpat nodes). However, this package is maintained in a separate repository since I want a very small dependency set for the blaze-html package.

That concludes the small BlazeHtml status update. Feedback is welcome, as always.

Comments

ce0f13b2-4a83-4c1c-b2b9-b6d18f4ee6d2