[plt-scheme] string->html/response

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Dec 17 09:33:05 EST 2008

On Dec 17, Jay McCarthy wrote:
> On Wed, Dec 17, 2008 at 6:43 AM, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
> > A simpler option might be to use an output format that allows you to include
> > raw unquoted strings in your X(H)TML output. This way so you never need to
> > parse the HTML from the blog post. Mirrors.plt allows this via its "!raw"
> > syntax.
> 
> Mirrors is great. But just to clarify, you can get raw unquoted
> strings in the X-expression syntax with cdata structs:
> 
> Examples:
> 
> (make-cdata #f #f "<b>bold</b>")
> 
> > (display
>    (xexpr->string
>     `(html
>       (body (h1 "Post Title")
>             ,(make-cdata #f #f
>                          "<p><b>Bold!</b></p>")))))
> <html><body><h1>Post Title</h1><p><b>Bold!</b></p></body></html>

And a scribble-syntax alternative:

  #reader scribble/reader
  #lang scheme
  
  (require (except-in xml cdata))
  
  (define (cdata . xs) (make-cdata #f #f (string-append* xs)))
  
  (display
   (xexpr->string
    @`html{@body{@h1{Post Title}
                 @,cdata{<p><b>Bold!</b></p>}}}))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.