[plt-scheme] Beautify (auto-)generated HTML-Code of servlets
Stefan Fehrenbach skrev:
> Danny Yoo wrote:
> I thought I could make the server use the library you pointed to or
> something in this direction.
>
>> we can do the conversion ourselves, and then pass that back as the
>> response.
>
> I'll think of this, would allow me to print the <!DOCTYPE...> too.
The normal xml-library provides pretty printing:
(require (lib "xml.ss" "xml"))
(define (xexpr->pretty-string xexpr)
(let ([os (open-output-string)])
(display-xml/content
(xexpr->xml xexpr) os)
(get-output-string os)))
> (display (xexpr->pretty-string
'(html (head (title "A title"))
(body "Foo"))))
<html>
<head>
<title>
A title
</title>
</head>
<body>
Foo
</body>
</html>
Generating a response can be done in many ways, for example
in the following non-standard way:
(require (planet "web.scm" ("soegaard" "web.plt" 1 0))
(lib "xml.ss" "xml"))
(define (xexpr->pretty-string xexpr)
(let ([os (open-output-string)])
(display-xml/content
(xexpr->xml xexpr)
os)
(get-output-string os)))
(make-response
(xexpr->pretty-string
'(html (head (title "A title"))
(body "Foo"))))
See
<http://ja.soegaard.net/planet/html/soegaard/web.plt/current/doc.txt>
for more on make-response.
--
Jens Axel Søgaard
<http://www.scheme.dk/blog/>