You are looking at historical revision 786 of this page. It may differ significantly from its current revision.
Small, functional and highly optimized HTML generator, generating srfi-40 streams of characters.
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)))
The html-stream egg was created by Alejandro Forero Cuervo.
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.
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 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>
(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 ...).
(html-stream (p "My name is " (b "Alejo") "."))
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.
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, img, br, hr, meta, input, link, frame, param, base.
remove-comments is provided as a convenience function to, well, remove HTML comments from a stream of characters.
- Adding support for more tags: base. Use documentation from wiki.
- Adding support for more tags: th font frameset strong em tt code blockquote link frame
- First release