[4] | 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)) |
---|
[85] | 15 | ;; These open tags will not have a newline prefixed, so as not to |
---|
| 16 | ;; introduce extraneous whitespace. |
---|
[25833] | 17 | (define xhtml-inline-elements '(a abbr acronym b bdo bdi big blink cite code dfn del |
---|
| 18 | em font i img ins kbd q s samp small span strike |
---|
| 19 | strong sub sup tt u var |
---|
| 20 | button input label select textarea |
---|
| 21 | ;; HTML5 |
---|
| 22 | audio canvas command date keygen mark meter output progress |
---|
| 23 | rp rt ruby time video |
---|
| 24 | )) |
---|
[85] | 25 | |
---|
[4] | 26 | (define (entag-xhtml tag elems) |
---|
[85] | 27 | (let ((entagged-result |
---|
| 28 | (if (and (pair? elems) (pair? (car elems)) |
---|
| 29 | (eq? '@ (caar elems))) |
---|
| 30 | (list #\< tag (cdar elems) |
---|
| 31 | (if (pair? (cdr elems)) |
---|
| 32 | (list #\> (cdr elems) "</" tag #\>) |
---|
| 33 | (if (memq tag xhtml-empty-elements) |
---|
| 34 | " />" |
---|
| 35 | (list #\> "</" tag #\>)))) |
---|
| 36 | (list #\< tag |
---|
| 37 | (if (pair? elems) |
---|
| 38 | (list #\> elems "</" tag #\>) |
---|
| 39 | (if (memq tag xhtml-empty-elements) |
---|
| 40 | " />" |
---|
| 41 | (list #\> "</" tag #\>))))))) |
---|
[4] | 42 | |
---|
[85] | 43 | (if (memq tag xhtml-inline-elements) |
---|
| 44 | entagged-result |
---|
| 45 | (cons #\newline entagged-result)))) |
---|