unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
To: guile-user <guile-user@gnu.org>, guile-devel <guile-devel@gnu.org>
Subject: avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html
Date: Sat, 20 Aug 2022 12:59:39 -0700	[thread overview]
Message-ID: <CA+XASoUW2m9WfYgxJs8CazX=d_nBtUDU456fVsJLPBLrvnB3jg@mail.gmail.com> (raw)

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


             reply	other threads:[~2022-08-20 19:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-20 19:59 Aleix Conchillo Flaqué [this message]
2022-08-20 21:48 ` avoid character encoding/escaping in sxml->xml or htmlprag's sxml->html 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é

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+XASoUW2m9WfYgxJs8CazX=d_nBtUDU456fVsJLPBLrvnB3jg@mail.gmail.com' \
    --to=aconchillo@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).