;; Render empty XHTML tags with an HTML-compatible close tag.
;; For HTML compatibility, EMPTY elements (according to DTD) should always
;; use the
form, and non-EMPTY elements should use the close-tag form.
;; From http://www.w3.org/TR/xhtml1/#guidelines:
;; C.2 Include a space before the trailing / and > of empty elements,
;; e.g.
,
and .
;; C.3 Also, use the minimized tag syntax for empty elements, e.g.
;;
, as the alternative syntax
allowed by XML gives
;; uncertain results in many existing user agents.
;; These elements use the minimized close tag form; all others will have
;; an explicit close tag.
(define xhtml-empty-elements '(base meta link hr br param img area input col))
;; These open tags will not have a newline prefixed, so as not to
;; introduce extraneous whitespace.
(define xhtml-inline-elements '(a abbr acronym cite code dfn em font kbd q samp strong var
b big i small strike sub sup tt u blink span))
(define (entag-xhtml tag elems)
(let ((entagged-result
(if (and (pair? elems) (pair? (car elems))
(eq? '@ (caar elems)))
(list #\< tag (cdar elems)
(if (pair? (cdr elems))
(list #\> (cdr elems) "" tag #\>)
(if (memq tag xhtml-empty-elements)
" />"
(list #\> "" tag #\>))))
(list #\< tag
(if (pair? elems)
(list #\> elems "" tag #\>)
(if (memq tag xhtml-empty-elements)
" />"
(list #\> "" tag #\>)))))))
(if (memq tag xhtml-inline-elements)
entagged-result
(cons #\newline entagged-result))))