[ANN] Hiccup 2.0.0-alpha1

261 views
Skip to first unread message

James Reeves

unread,
Jan 14, 2017, 9:17:24 PM1/14/17
to clo...@googlegroups.com
I'd like to tentatively announce the first alpha version of Hiccup 2.0.0.

This release introduces automatically escaping of strings, which has been a frequently requested feature. Hiccup 1.0 had no way of distinguishing between a string of text and a fragment of HTML, so for version 2.0 a new type has been introduced to represent the latter.

A lot of projects depend upon Hiccup, and after thinking about it for a while, and watching Rich's Spec-ulation talk, I decided to introduce a new namespace rather than break backward compatibility. So although Hiccup 2.0.0 is a major version change, it should be backward compatible with version 1.0.

The new namespace is hiccup2.core, and it works like this:

  (require '[hiccup2.core :refer [html raw]])

  (str (html [:span "one < two"]))
  ;=> "<span>one &lt; two</span>"

Notice that now strings are escaped by default, but we also need to explicitly convert the HTML fragment into a string by using clojure.core/str.

By using a compiled intermediate format, we gain a lot more potential flexibility. For example, possible future feature currently under consideration is to support different ways of formatting the HTML. Using an intermediate format allows us to do this after pre-compilation has taken place.

Because this is an alpha release, the hiccup2.core namespace is not set in stone, but it does seem to be the simplest solution to the problem of incompatibility. Suggestions for better ways to solve this are welcome and encouraged.

As well as escaping strings, additional syntax sugar for attributes has been introduced. This should be familiar to anyone using Reagent:

  (str (html [:span {:class ["foo" "bar"]} "example"]))
  ;=> "<span class=\"foo bar\">example</span>"

  (str (html [:span {:style {:color "red"}} "example"]))
  ;=> "<span style=\"color:red;\">example</span>"

Please give the alpha release a spin, and if there are any incompatibilities please let me know.

- James

Bryan Maass

unread,
Jan 15, 2017, 5:49:38 PM1/15/17
to Clojure, ja...@booleanknot.com
Fantastic news! This may call for an update to http://hiccup.space
Reply all
Reply to author
Forward
0 new messages