trivia: towards a more modern HTML: closing slash within empty HTML

elements
*new: EMIT-EMPTY-TAG
*use EMIT-EMPTY-TAG instead of EMIT-TAG where appropriate
This commit is contained in:
vibr 2005-04-14 21:15:21 +00:00
parent e8dc69b745
commit 4c1e1a16a8
4 changed files with 30 additions and 9 deletions

View File

@ -368,7 +368,7 @@
((directory) "[DIR ]") ((directory) "[DIR ]")
(else "[????]")))) (else "[????]"))))
(if icon-name (if icon-name
(emit-tag port 'img (emit-empty-tag port 'img
(cons 'src icon-name) (cons 'src icon-name)
(cons 'alt tag-name)) (cons 'alt tag-name))
(display tag-name port)) (display tag-name port))
@ -433,16 +433,16 @@
(with-tag port pre () (with-tag port pre ()
(if blank-icon (if blank-icon
(display "[ ]" port) (display "[ ]" port)
(emit-tag port 'img (emit-empty-tag port 'img
(cons 'src blank-icon) (cons 'src blank-icon)
(cons 'alt " "))) (cons 'alt " ")))
(write-string "Name " port) (write-string "Name " port)
(write-string "Last modified " port) (write-string "Last modified " port)
(write-string "Size " port) (write-string "Size " port)
(write-string "Description" port) (write-string "Description" port)
(emit-tag port 'hr) (emit-empty-tag port 'hr)
(if back-icon (if back-icon
(emit-tag port 'img (emit-empty-tag port 'img
(cons 'src back-icon) (cons 'src back-icon)
(cons 'alt "[UP ]")) (cons 'alt "[UP ]"))
(display "[UP ]" port)) (display "[UP ]" port))
@ -452,7 +452,7 @@
(write-string "Parent directory" port)) (write-string "Parent directory" port))
(write-crlf port))) (write-crlf port)))
(let ((n-files (directory-index req fname port options))) (let ((n-files (directory-index req fname port options)))
(emit-tag port 'hr) (emit-empty-tag port 'hr)
(format port "~d files" n-files)))))))))))) (format port "~d files" n-files))))))))))))
((string=? request-method "POST") ((string=? request-method "POST")

View File

@ -234,7 +234,7 @@
(string-append "(" file ")" node)))) (string-append "(" file ")" node))))
(define (display-icon file alt out) (define (display-icon file alt out)
(emit-tag out 'img (emit-empty-tag out 'img
(cons 'src file) (cons 'src file)
(cons 'alt alt) (cons 'alt alt)
(cons 'align "bottom"))) (cons 'align "bottom")))
@ -282,18 +282,18 @@
(emit-title out (string-append "Info Node: " (emit-title out (string-append "Info Node: "
(unparse-node-name file node))) (unparse-node-name file node)))
(with-tag out h1 () (with-tag out h1 ()
(emit-tag out 'img (emit-empty-tag out 'img
(cons 'src (icon-name 'info)) (cons 'src (icon-name 'info))
(cons 'alt "Info Node") (cons 'alt "Info Node")
(cons 'align 'bottom)) (cons 'align 'bottom))
(write-string (unparse-node-name file node) out)) (write-string (unparse-node-name file node) out))
(emit-tag out 'hr) (emit-empty-tag out 'hr)
(maybe-display-header next (icon-name 'next) "[Next]") (maybe-display-header next (icon-name 'next) "[Next]")
(maybe-display-header previous (icon-name 'previous) "[Previous]") (maybe-display-header previous (icon-name 'previous) "[Previous]")
(maybe-display-header up (icon-name 'up) "[Up]") (maybe-display-header up (icon-name 'up) "[Up]")
(if (or next previous up) (if (or next previous up)
(emit-tag out 'hr))) (emit-empty-tag out 'hr)))
;; Text ;; Text

View File

@ -70,6 +70,26 @@
attrs) attrs)
(display #\> out))) (display #\> out)))
;;; Empty elements, e.g. <hr />
(define (emit-empty-tag out tag . attrs)
(let ((out (fmt->port out)))
(display "<" out)
(display tag out)
(for-each (lambda (attr)
(display #\space out)
(cond ((pair? attr) ; name="val"
(display (car attr) out)
(display "=\"" out) ; Should check for
(display (cdr attr) out) ; internal double-quote
(display #\" out)) ; etc.
(else
(display attr out)))) ; name
attrs)
(display " /" out)
(display #\> out)))
;;; </tag> ;;; </tag>

View File

@ -15,6 +15,7 @@
(define-interface htmlout-interface (define-interface htmlout-interface
(export emit-tag (export emit-tag
emit-empty-tag
emit-close-tag emit-close-tag
emit-p emit-p