html is a simple library for generating HTML in the spirit of Spinneret and
Hiccup. html has no dependencies.
| Compiler | Compiles? |
|---|---|
| SBCL | ✅ |
| ECL | ✅ |
| Clasp | ✅ |
| ABCL | ✅ |
| CCL | ✅ |
| Clisp | ✅ |
| Allegro | ✅ |
| LispWorks | ❓ |
With a focus on simplicity, html provides the bare necessities for generating
HTML. Seekers of any higher sophistication should try Spinneret.
In the examples below, (in-package :html) is used for brevity, and it is assumed
that in your own code you will prefix all calls with html:.
For HTML with predetermined content, use the html macro:
(in-package :html)
(macroexpand (html (:raw "<!DOCTYPE html>")
(:html
(:head (:meta :charset "utf-8"))
(:body (:div :id "foo"
:class "bar"
(:span "hello"))))))<!DOCTYPE html>
<HTML>
<HEAD>
<META CHARSET="utf-8">
</HEAD>
<BODY>
<DIV ID="foo" CLASS="bar">
<SPAN>
hello
</SPAN>
</DIV>
</BODY>
</HTML>
Here we see examples of:
- Defining elements as lists, with a keyword indicating the tag name.
- Nesting elements with child lists.
- Standalone (i.e. “void”) elements like
meta. - Raw HTML injection via the
:rawpseudo-tag. - Attributes via keyword-string pairs.
- CAPITAL LETTERS. This is Lisp after all ;)
Naturally you’ll also want to dynamically inject content into certain elements.
The expansion logic used within the html macro is a standalone function named
expand that you can also call yourself, provided you have a stream on hand.
(in-package :html)
(with-output-to-string (stream)
(let ((name "Jack"))
(expand stream `(:span ,name))))<SPAN> Jack </SPAN>
- Spinneret
- Clip: External HTML templating
- Hiccup (Clojure)
- Awesome CL - HTML Generators