[plt-scheme] Re: HTML escaping questions

From: David Van Horn (dvanhorn at cs.uvm.edu)
Date: Mon Feb 23 17:47:14 EST 2004

Terrence Brannon wrote:
> Thanks to Dougo, I got the XML library loaded. I have a coupla questions:
> 1/ Given these two values for text and banner:
> (define text "pretty & red")
> (define banner "\"here is the banner\"")
> (empty-tag-shorthand html-empty-tags)
> (write-xml/content (xexpr->xml `(html (head (title ,banner))
>                       (body ((bgcolor "white"))
>                         ,text)))
> The ampersand is converted to an XML entity but the quotation marks are not

You can do this "by hand" if needed:

(define text "pretty & red")
(define banner '(quot "here is the banner" quot))

     `(html (head (title , at banner))
            (body ((bgcolor "white"))

> 2/ I have some files of javascript that I need to place in a website. 
> How do I create an X-expr that does not atttempt any HTML escaping on 
> its input string?

You can put javascript in comments, which will prevent the character escaping:

     `(html (head (title , at banner))
            (body ((bgcolor "white"))
                  ,(make-comment "your javascript here & here")

I don't know how to do this in the case of `(a ((href "js here & here")) ...) 
and the like.  Not escaping would cause the output to be invalid XML.


Posted on the users mailing list.