write-html added by kon on Sun Jun 30 15:04:02 2024


;FIXME doesn't recognize html elements w/ semantic issues & shortcut trailing />
(define (write-html sxml #!optional label (ns '()))
  (import sxml-serializer)
  ;(when label (print "<!-- " label " -->"))
  ;Doesn't write out DECL so explicit, but does start w/ a \n
  (display "<!DOCTYPE HTML>")
  (handle-exceptions exn
    (log-error "serialize-sxml failed: ~S | ~S)" label (condition->list exn))
    ;no CDATA
    (serialize-sxml sxml
      output: (current-output-port)
      indent: "  "
      method: 'html
      ns-prefixes: `(,@ns ,@conventional-ns-prefixes)) ) )

#; ;XXX
(define (write-html sxml #!optional label (ns '()))
  (import sxml-transforms)
  (let ((labeled-sxml
          (if label `((*COMMENT* ,label) ,@sxml)
              sxml)) )
    (handle-exceptions exn
      (log-error "SXML->HTML failed: ~S | ~S)" label (condition->list exn))
      (SXML->HTML labeled-sxml) ) ) )

#; ;Doesn't handle <, etc in script right
(define (write-html sxml #!optional label (ns '()))
  (import sxml-serializer)
  (let ((labeled-sxml
          (if label `((*COMMENT* ,label) ,@sxml)
            sxml)) )
    (handle-exceptions exn
      (log-error "serialize-sxml failed: ~S | ~S)" label (condition->list exn))
      ;no CDATA
      (serialize-sxml labeled-sxml
        output: (current-output-port)
        indent: "  "
        method: 'xml
        ns-prefixes: `(,@ns ,@conventional-ns-prefixes)) ) ) )

#; ;Doesn't handle entities on output well
(define (write-html sxml #!optional label)
  (when label (print "<!--" label "-->"))
  (handle-exceptions exn
    (log-error "sxml-display-as-html failed: ~S | ~S)" label (condition->list exn))
    ;
    (sxml-display-as-html sxml) ) )