1 Introduction
2 Foreign Filters
error-html-writing-foreign-filter
current-html-writing-foreign-filter
3 Writing
3.1 Writing Attributes
write-html-attribute-value-char
write-html-attribute-value-string
write-html-attribute-value-part/ fixed
write-html-attribute-value
write-html-attribute
write-html-attribute-list
write-html-attribute-or-list
3.2 Writing Other
write-html-decl/ fixed
write-html-pi/ fixed
write-html-entity-ref
3.3 Writing HTML
write-html
xexp->html
4 History
5 Legal
Version: 0.1

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

Neil Van Dyke

License: LGPL 3   Web: http://www.neilvandyke.org/racket-html-writing/

 (require (planet neil/html-writing:1:=0))

1 Introduction

Note: This package is in a state of active development, and some interface changes, perhaps not backward-compatible, are expected. Documentation is gravely lacking.

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 html-parsing.

For a different way of writing HTML from chunks of hand-constructed xexp, see the html-template package.

2 Foreign Filters

(error-html-writing-foreign-filter object    
  context)  any/c
  object : any/c
  context : any/c

!!!

(current-html-writing-foreign-filter)  any/c
(current-html-writing-foreign-filter x)  void?
  x : any/c

!!!

3 Writing

!!! The two most common procedures in html-writing for writing HTML from an 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 xexp.

3.1 Writing Attributes

(write-html-attribute-value-char chr out)  any/c
  chr : any/c
  out : any/c

!!!

(write-html-attribute-value-string str out)  any/c
  str : any/c
  out : any/c

!!!

(write-html-attribute-value-part/fixed val    
  out    
  foreign-filter)  any/c
  val : any/c
  out : any/c
  foreign-filter : any/c

!!!

(write-html-attribute-value attr    
  out    
  foreign-filter)  any/c
  attr : any/c
  out : any/c
  foreign-filter : any/c

!!!

(write-html-attribute attr    
  out    
  foreign-filter)  any/c
  attr : any/c
  out : any/c
  foreign-filter : any/c

!!!

(write-html-attribute-list attr-list    
  out    
  foreign-filter)  any/c
  attr-list : any/c
  out : any/c
  foreign-filter : any/c

!!!

(write-html-attribute-or-list attr-or-list    
  out    
  foreign-filter)  any/c
  attr-or-list : any/c
  out : any/c
  foreign-filter : any/c

!!!

3.2 Writing Other

(write-html-decl/fixed xexp out)  any/c
  xexp : any/c
  out : any/c

!!!

(write-html-pi/fixed xexp out)  any/c
  xexp : any/c
  out : any/c

!!!

(write-html-entity-ref ref out)  any/c
  ref : any/c
  out : any/c

!!!

3.3 Writing HTML

(write-html xexp out foreign-filter)  any/c
  xexp : any/c
  out : any/c
  foreign-filter : any/c

Writes a conventional HTML transliteration of the 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-xexp (“foreign”) object encountered in xexp, and should yield 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.")))))

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 is

another paragraph.</p></body></html>

(xexp->html xexp)  any/c
  xexp : any/c

Yields an HTML encoding of 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 (c) 2004–2011 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 (LGPL 3), 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.

Standard Documentation Format Note: The API signatures in this documentation are likely incorrect in some regards, such as indicating type any/c for things that are not, and not indicating when arguments are optional. This is due to a transitioning from the Texinfo documentation format to Scribble, which the author intends to finish someday.