source: project/release/4/sxml-transforms/trunk/chicken/xhtml.scm @ 20048

Last change on this file since 20048 was 85, checked in by Jim Ursetto, 15 years ago

Update sxml-transforms to version 1.1:
Improve inline element whitespace handling; add '&' rule.

File size: 1.8 KB
Line 
1;; Render empty XHTML tags with an HTML-compatible close tag.
2;; For HTML compatibility, EMPTY elements (according to DTD) should always
3;; use the <br /> form, and non-EMPTY elements should use the close-tag form.
4;; From http://www.w3.org/TR/xhtml1/#guidelines:
5
6;; C.2 Include a space before the trailing / and > of empty elements,
7;; e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />.
8;; C.3 Also, use the minimized tag syntax for empty elements, e.g.
9;; <br />, as the alternative syntax <br></br> allowed by XML gives
10;; uncertain results in many existing user agents.
11
12;; These elements use the minimized close tag form; all others will have
13;; an explicit close tag.
14(define xhtml-empty-elements '(base meta link hr br param img area input col))
15;; These open tags will not have a newline prefixed, so as not to
16;; introduce extraneous whitespace.
17(define xhtml-inline-elements '(a abbr acronym cite code dfn em font kbd q samp strong var
18                                b big i small strike sub sup tt u blink span))
19
20(define (entag-xhtml tag elems)
21  (let ((entagged-result
22         (if (and (pair? elems) (pair? (car elems))
23                  (eq? '@ (caar elems)))
24             (list #\< tag (cdar elems)
25                   (if (pair? (cdr elems))
26                       (list #\> (cdr elems) "</" tag #\>)
27                       (if (memq tag xhtml-empty-elements)
28                           " />"
29                           (list #\> "</" tag #\>))))
30             (list #\< tag
31                   (if (pair? elems)
32                       (list #\> elems "</" tag #\>)
33                       (if (memq tag xhtml-empty-elements)
34                           " />"
35                           (list #\> "</" tag #\>)))))))
36
37    (if (memq tag xhtml-inline-elements)
38        entagged-result
39        (cons #\newline entagged-result))))
Note: See TracBrowser for help on using the repository browser.