1 Introduction
2 Foreign Filters
current-html-writing-foreign-filter
3 Writing Procedures
3.1 Writing Attributes
3.2 Writing Other
3.3 Writing HTML
write-html
xexp->html
4 History
5 Legal
Version: 2:0

html-writing: Writing HTML from SXML/xexp in Racket

Neil Van Dyke

 (require (planet neil/html-writing:2:0))

1 Introduction

Warning: State of flux. Documentation under construction.
The html-writing package provides support for writing HTML encoded as SXML/xexp as HTML.
This can be used for hand-constructed HTML, HTML constructed by program, or emitting HTML that has been read via the html-parsing package.
For a complementary way of writing HTML from SXML/xexp, see the html-template package.

2 Foreign Filters

(current-html-writing-foreign-filter)  !!!
(current-html-writing-foreign-filter ff)  void?
  ff : !!!
!!!

3 Writing Procedures

!!! The two most common procedures in html-writing for writing HTML from an SXML/xexp representation are write-html and xexp->html. These are perhaps most useful for emitting the result of parsed and transformed input HTML. They can also be used for emitting HTML from generated or handwritten SXML/xexp.

3.1 Writing Attributes

3.2 Writing Other

3.3 Writing HTML

(write-html xexp out)  void?
  xexp : xexp?
  out : output-port?
Writes a conventional HTML transliteration of the SXML/xexp xexp to output port out. If out is not specified, the default is the current output port. HTML elements of types that are always empty are written using HTML4-compatible XHTML tag syntax.
!!! If foreign-filter is specified, it is a procedure of two argument that is applied to any non-SXML/xexp (“foreign”) object encountered in xexp, and should yield SXML/xexp. The first argument is the object, and the second argument is a symbol for the context. The possible symbols are: !!!
No inter-tag whitespace or line breaks not explicit in xexp is emitted. The xexp should normally include a newline at the end of the document. For example:
(write-html
 '((html (head (title "My Title"))
         (body (@ (bgcolor "white"))
               (h1 "My Heading")
               (p "This is a paragraph.")
               (p "This is another paragraph."))))
 (current-output-port))
produces the output:

<html><head><title>My Title</title></head><body bgcolor="white"><h1>My Heading</h1><p>This is a paragraph.</p><p>This isanother paragraph.</p></body></html>

(xexp->html xexp)  string?
  xexp : xexp?
Yields an HTML encoding of SXML/xexp xexp as a string. For example:
> (xexp->html
   (html->xexp
    "<P>This is<br<b<I>bold </foo>italic</ b > text.</p>"))
  "<p>This is<br><b><i>bold italic</i></b> text.</p>"
Note that, since this procedure constructs a string, it is normally best used when the HTML is small. When encoding HTML documents of conventional size, write-html is likely more efficient.

4 History

5 Legal

Copyright 2004 – 2012 Neil Van Dyke. This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License,or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.