Some Practical Clojure Examples
← prev | next →     Top-level ToC     /html.html     (printable version)

You can write html derived directly from Clojure code using hiccup:

#!/usr/bin/env inlein

'{:dependencies [[org.clojure/clojure "1.8.0"]
                 [hiccup "1.0.5"]]}

(require 'hiccup.page)

(defn main
  []
  (println (hiccup.page/html5
            [:head [:title "Example"]]
            [:body
             [:p "hi"]
             [:ul (for [i (range 3)]
                    [:li i])]])))

;;----
(main)

Results in:

<!DOCTYPE html>
<html>
<head><title>Example</title></head>
<body><p>hi</p>
<ul>
  <li>0</li>
  <li>1</li>
  <li>2</li>
</ul>
</body>
</html>

(Output formatted for readability.)