Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<script> tag escapes Javascript code #13

Open
defaultxr opened this issue Nov 23, 2024 · 0 comments
Open

<script> tag escapes Javascript code #13

defaultxr opened this issue Nov 23, 2024 · 0 comments

Comments

@defaultxr
Copy link

With Flute and Parenscript, something like this doesn't work:

(h (script (ps (dotimes (n 3)
                 (alert "test")))))

because the result looks like this:

<script>
  (function () {
    for (var n = 0; n &lt; 3; n += 1) {
        alert('test');
    };
})();
</script>

Note that the < in the Javascript is escaped to &lt;, which seems to be invalid Javascript, as it causes the browser's JS parser to get confused and throw a syntax error. But the following, with < instead of &lt;, does run:

<script>
  (function () {
    for (var n = 0; n < 3; n += 1) {
        alert('test');
    };
})();
</script>

Since the contents of a <script> tag are parsed differently by the browser (i.e. HTML escape codes are not interpreted), it seems like maybe the default behavior of flute:script should be to not HTML-escape the content.

In the meantime, a workaround seems to be manually setting flute:*escape-html* to nil:

(h (let ((flute:*escape-html* nil))
     (script (ps (dotimes (n 3)
                   (alert "test"))))))

I'm not an HTML/JS pro though, nor a Flute pro, so if I should be doing this a different way instead, let me know.

(And yes, I know that <script src="..."></script> can also be used, but it seems more ergonomic that both use-cases would be handled correctly by Flute. IMO anyway)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant