unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html
@ 2022-08-20 19:59 Aleix Conchillo Flaqué
  2022-08-20 21:48 ` Maxime Devos
  0 siblings, 1 reply; 7+ messages in thread
From: Aleix Conchillo Flaqué @ 2022-08-20 19:59 UTC (permalink / raw)
  To: guile-user, guile-devel

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="fib.js"> 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-08-21 22:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-20 19:59 avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html Aleix Conchillo Flaqué
2022-08-20 21:48 ` Maxime Devos
2022-08-21  0:05   ` Aleix Conchillo Flaqué
2022-08-21  5:09     ` tomas
2022-08-21 10:16     ` Maxime Devos
2022-08-21 10:23       ` tomas
2022-08-21 22:34       ` Aleix Conchillo Flaqué

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).