[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.17 text.html-lite - Simple HTML document construction

Module: text.html-lite
Provides procedures to construct an HTML document easily. For example, you can construct an HTML table by the following code:
  (html:tr (html:th "Item No") (html:th "Quantity"))
  (html:tr (html:td 1) (html:td 120))
  (html:tr (html:td 2) (html:td 30))
  (html:tr (html:td 3) (html:td 215)))
See the description of html:element below for details.

This module does little check for the constructed html documents, such as whether the attributes are valid, and whether the content of the element matches DTD. It does not provide a feature to parse the html document neither. Hence the name `lite'.

Function: html-escape
Function: html-escape-string string
Escapes the "unsafe" characters in HTML. html-escape reads input string from the current input port and writes the result to the current output port. html-escape-string takes the input from string and returns the result in a string.

Function: html-doctype &keyword type
Returns a doctype declaration for an HTML document. type can be either one of :strict, :transitional, or :frameset, corresponding HTML4.01 strict, transitional or frameset DTD, respectively.

Function: html:element args ...
Construct an HTML element element. Right now, the following elements are provided. (The elements defined in HTML 4.01 DTD, http://www.w3.org/TR/html4/sgml/dtd.html).
a        abbr       acronym    address     area      b
base     bdo        big        blockquote  body      br
button   caption    cite       code        col       colgroup
dd       del        dfn        div         dl        dt
em       fieldset   form       h1          h2        h3
h4       h5         h6         head        hr        html
i        img        input      ins         kbd       label
legend   li         link       map         meta      noscript
object   ol         optgroup   option      p         param
pre      q          samp       script      select    small
span     strong     style      sub         sup       table
tbody    td         textarea   tfoot       th        thead
title    tr         tt         ul          var

The result of these functions is a tree of text segments, which can be written out to a port by write-tree or can be converted to a string by tree->string (See section 11.20 text.tree - Lazy text construction).

You can specify attributes of the element by using a keyword-value notation before the actual content.
(tree->string (html:a :href "http://foo/bar" "foobar"))
  "<a href=\"http://foo/bar\">foobar</a>\n"

  (html:table :width "100%" :cellpading 0 "content here"))
  "<table width=\"100%\" cellpadding=\"0\">content here</table>\n"

The boolean value given to the attribute has a special meaning. If #t is given, the attribute is renfered without a value. If #f is given, the attribute is not rendered.
(tree->string (html:table :border #t))
  => "<table border></table>\n"

(tree->string (html:table :border #f))
  => "<table></table>\n"

Special characters in attribute values are escaped by the function, but the ones in the content are not. It is caller's responsibility to escape them.

The functions signal an error if a content is given to the HTML element that doesn't take a content. They do not check if the given attribute is valid, neither if the given content is valid for the element.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html