Skip to content

fosskers/html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

html: Simple HTML generation

html is a simple library for generating HTML in the spirit of Spinneret and Hiccup. html has no dependencies.

Table of Contents

Compatibility

CompilerCompiles?
SBCL
ECL
Clasp
ABCL
CCL
Clisp
Allegro
LispWorks

Usage

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:.

Static 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 :raw pseudo-tag.
  • Attributes via keyword-string pairs.
  • CAPITAL LETTERS. This is Lisp after all ;)

Dynamic Content

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>

See Also

About

Simple HTML generation.

Topics

Resources

License

Stars

Watchers

Forks

Contributors