Search code examples
javascriptlispcommon-lisphunchentootcl-who

CL-WHO is always starting with a single quote


My issue is that CL-WHO begins each expression with a single quotation market when it turns the Lisp S-expressions into html output. This is okay most of the time, but it is an issue since I am linking my file to an external javascript file. I am trying to make this project simple, and since none of the javascript developers on my team know Common Lisp, using parenscript is likely out of the equation. Here is an example of my issue and one of the errors in my program:

:onclick "alertUser('id')"

When a particular element is pressed within the html document, this should trigger a JavaScript function called alertUser, and the id of the tag should be passed to the JavaScript function as an argument. But no matter what I do, CL-WHO will convert that string into single quotation marks, so I end up with an invalid expression. Here is what that code converts to:

onclick='alertUser('id')'>

Everything is a single quotation so 'alertUser(' is passed as the first string which is obviously invalid and I receive a syntax area in my developer tools. I thought that I could solve this problem by using the format function with escape characters. This would equate to:

CL-USER> (format t "\"alertUser('id')\"")
"alertUser('id')"
NIL
CL-USER> 

But when I try that with CL-WHO:

:onclick (format nil "\"alertUser('id')\"")

That translates to:

onclick='"alertUser('locos-tacos-order')"'>

Which is also invalid html. As you can see, CL-WHO will start with a single quote no matter what. Next I tried the CL-WHO fmt function:

:onclick (fmt "\"alertUser('locos-tacos-order')\"")

When I use the fmt function it gets rid of my :onclick expression entirely when it is converted to html!:

id='id'"alertUser('id')">

Lastly I tried the str function, and got similarly invalid output to my original attempt:

onclick='"alertUser('id')"'

Obviously if I code this in pure html it will look like:

onclick="alertUser('id')">

Which is valid. My question is simply how do I enable CL-WHO to use double quotation marks in these situations instead of single quotation marks?


Solution

  • @jkiiski was has the correct answer in the comments underneath my question, but I wanted to post the answer so that anyone with a similar issue in the future can resolve the problem. As @jkiiski said, there is a variable called ATTRIBUTE-QUOTE-CHAR in the cl-who package that defaults to #\'. You can simply set that variable to #\" instead in order for the default quotations used to be double quotation marks:

    (setf *attribute-quote-char* #\")
    

    After adding that line of code near the top of the file my html defaults to:

    onclick="alertUser('id')"
    

    and now the javascript can execute properly. Credit to @jkiiski for a correct answer.