1. html-stream
    1. Introduction
    2. Examples
      1. Generating HTML
      2. Removing HTML comments from a stream
    3. Authors
    4. License
    5. Requirements
    6. Rendering an HTML stream
      1. Tag definition
      2. Shorthand for tag definition
      3. Other expresions
    7. Tags recognized:
    8. Removing comments
    9. Version history
      1. 1.5
      2. 1.4
      3. Previos releases

html-stream

Introduction

Small, functional and highly optimized HTML generator, generating srfi-40 streams of characters.

Examples

Generating HTML

The following code evaluates to a stream of characters in HTML:

(use html-stream)

(stream->string
 (html-stream
  (p (i "The squares of the first " (b "five") " integers are:"))
  (ul
   (apply stream-append
     (map (lambda (x) (html-stream (li (* x x)))) (iota 5 1))))))

Removing HTML comments from a stream

The following code reads HTML from the current-input-port, removes HTML comments and writes the output:

(use stream-ext html-stream)

(write-stream (remove-comments (port->stream (current-input-port)))

Authors

The html-stream egg was created by Alejandro Forero Cuervo.

License

The html-stream egg for Chicken Scheme is in the public domain and may be reproduced or copied without permission from its author. Citation of the source is appreciated.

Requirements

This egg depends on the following:

Rendering an HTML stream

(html-stream tag1 ...)

html-stream is used to generate HTML from a simple and straight-forward format. A (html-stream ...) form will evaluate to a srfi-40 stream of characters with its associated contents.

Each expresion inside a html-stream macro may have any of the following forms:

Tag definition

((tag param0 ...) arg0 ...)

If tag is recognized as the name of an HTML tag, this expresion expands to an HTML tag with the arguments specified by the param0 ... list. This list must have an even number of elements: the even elements must be symbols for the parameter names, followed by their actual values (which must have a type accepted by ->stream-char).

The forms arg0 ... are parsed recursively and their values included inside the HTML tag.</p>

Examples:

(html-stream
 ((a href "index.html" title "Some Title") "Home Page"))
==> #,(stream "<a href='index.html' title='Some Title'>Home Page</a>")
(html-stream
 ((img src "photo.jpeg" height 150 width 150 alt "Yes")))
==> #,(stream "<img src='photo.jpeg' height=150 width=150 alt='Yes'/>")

Shorthand for tag definition

(tag arg0 ...)

If tag is the name of an HTML tag, an HTML tag with no parameters is generated. The arguments arg0 ... are parsed recursively.

Note that this form is just an alias for ((tag) arg0 ...).

Examples:

(html-stream (p "My name is " (b "Alejo") "."))

Other expresions

Other expresions not having any of the two forms above will be evaluated (at runtime), their results passed to ->stream-char and the resulting streams added to the result.

Tags recognized:

The library recognizes the following HTML tags: style, html, head, title, body, p, a, b, i, ul, ol, li, dl, dt, dd, table, tr, td, thead, th, tbody, h1, h2, h3, h4, h5, h6, div, span, small, big, script, select, option, textarea, center, form, pre, frameset, strong, em, tt, code, blockquote, object, embed, label, img, br, hr, meta, input, link, frame, param, base.

Removing comments

(remove-comments str)

remove-comments is provided as a convenience function to, well, remove HTML comments from a stream of characters.

Version history

1.5

1.4

Previos releases

1.3
Adding support for more tags: label. Proper escaping of characters inside tag parameters, to make the output closer to being XML conformant.
1.2
Adding support for more tags: base. Use documentation from wiki.
1.1
Adding support for more tags: th, font, frameset, strong, em, tt, code, blockquote, link, frame.
1.0
First release