guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html


From: Aleix Conchillo Flaqué
Subject: avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html
Date: Sat, 20 Aug 2022 12:59:39 -0700

Hi there,

I have a GuileScript example that it's basically a web server written in Guile that returns a basic HTML and also a <script> with some code generated with GuileScript. Something like this:

------------------------------------------------
(use-modules ((language guilescript compile) #:prefix gs:) ....)

(define js-fibonacci
  '(begin
     (define (fib n)
       (if (<= n 1)
           1
           (+ (fib (- n 2)) (fib (- n 1)))))

     (define (computeFibonacci)
       (let ((elem (js-invoke document 'getElementById "number"))
             (n (js-ref elem 'value)))
         (alert (+ "Fibonacci of " n " is " (fib n)))))

     (alert "Let's compute some fibonacci numbers!")))

(define js-script
  (receive (js _)
      (gs:compile js-fibonacci)
    js))

;;
;; This is the web page.
;;
(define (main-form request body)
  `(html
    (head (title "Fibonacci GuileScript Server")
          (script ,js-script))
    (body
     (input (@ (id "number") (type "text") (size "50") (value "")))
     (button (@ (type "button") (onclick "computeFibonacci()")) "Compute Fibonacci"))))
------------------------------------------------

However, I'm not able to find a way to avoid character encoding/escaping and the generated code inside <script> will always have "&lt;", etc. And <script> is a place where encodings can be avoided. This is true for both Guile and guile-lib's (htmlprag), even though htmlprag's escapes less characters (e.g. double quotes).

One way I found to solve this was to have <script src="" and then have a handler for fib.js that would just return the transpiled string. But it's not as nice, it's extra work and it's also an additional roundtrip to the server.

Has anyone ran into this issue? Would is make sense to add a keyword argument to (sxml->xml)? For example, (sxml->xml SXML PORT #:escape #f).

Best,

Aleix



reply via email to

[Prev in Thread] Current Thread [Next in Thread]