Generates HTML output from Lisp.
If stream is supplied, var is bound
to stream and output is written to that. If
stream is not supplied, then var
should previously have been bound to the desired
output stream.
The HTML to be generated is specified in Lisp syntax.
For example, see the following (included with the
code):
(defun create-blank-page (s title)
(with-html-output (s)
(:html
(:head
(:title (esc title))
(lfd))
(:body
(:h1 (esc title))
(lfd)
"<!-- Body here -->"
(lfd)))))
This generates a blank page with the given title. The
list beginning :html is output as a begin
<HTML> tag, followed by the tag
content (the rest of the list after the keyword
html), and lastly an end
</HTML> tag... and so on.
The body of with-html-output consists of
HTML in Lisp syntax (`LHTML') and/or Lisp code. For
each form:
If the form is a keyword symbol it corresponds to an
element with an empty content model - :br
corresponds to <br>;
If the form is a list beginning with a keyword
symbol it corresponds to an element with no attributes.
If the list is empty and the element is defined as empty
(below) then no closing tag is generated. (:p
"foo") corresponds to
<p>foo</p>;
If the form is a list beginning with a list which
begins with a keyword symbol it corresponds to an
element with attributes. The attributes and values are
given by keyword `arguments'. ((:a :href "foo")
"bar") corresponds to <a href
"foo">bar</a>;
If the form is a string it corresponds to that
literal string in the output; if the form is a character
it corresponds to that character;
Otherwise, the form is Lisp code which is evaluated
in the normal way.
with-html-output understands various
shorthands for specifying particular HTML output,
implemented as local macros:
- htm
- re-enters HTML mode, for instance
from within Lisp code. This is essentially the same
as a nested
with-html-output
- fmt
- shorthand for
(format s
...) where s is the stream on which
output is being generated
- esc
- escapes its argument string, quoting
things that are magic to HTML. See
escape-string below.
- lfd
- outputs a linefeed on the output stream