1

The usual way to generate HTML using CL-WHO is by using the macros with-html-output and with-html-output-to-string. This uses special syntax. For example:

(let ((id "greeting")
      (message "Hello!"))
  (cl-who:with-html-output-to-string (*standard-output*)
    ((:p :id id) message)))

Is it possible to write the data ((:p :id id) message) as a list instead of using the macro syntax shown above? For example, I would like to define the HTML as a list like this:

(let* ((id "greeting")
       (message "Hello!")
       (the-html `((:p :id ,id) ,message)))
  ;; What should I do here to generate HTML using CL-WHO?
  )

Can CL-WHO take a normal Lisp list and produce HTML from the list?

Flux
  • 9,805
  • 5
  • 46
  • 92
  • You might like [Ten](https://github.com/mmontone/ten), it's a templating engine but we can write any Lisp inside it. Could be a middle ground for you, you will be able to write `the-html` with the placeholders and already with some logic. – Ehvince Nov 15 '21 at 12:32
  • AllegroServe's htmlgen is able to generate HTML from Lisp lists, but it's only for Allegro Common Lisp. There's a "Portable AllegroServe" fork of AllegroServe that supports other Common Lisp implementations, but it appears to be unmaintained and its htmlgen still does not support HTML5. – Flux Nov 15 '21 at 12:53
  • Looks like [Flute](https://github.com/ailisp/flute) allows that. Its building blocks are just functions, so we can pass in variables. – Ehvince Nov 16 '21 at 22:25
  • There's [html.lisp](https://gist.github.com/markasoftware/ab357f1b967b3f656d026e33fec3bc0e), which generates HTML from lists. – Flux May 13 '22 at 06:58

1 Answers1

0

You want to insert code into an expression.

Actually you would need eval:

(let* ((id "greeting")
       (message "Hello!")
       (the-html `((:p :id ,id) ,message)))
  (eval `(cl-who:with-html-output-to-string (*standard-output*)
    ,the-html)))

But this is not good to use eval. But a macro contains an implicite eval. I would define a macro for this and call the macro:

(defun html (&body body)
  `(cl-who:with-html-output-to-string (*standard-output*)
    ,@body))

;; but still one doesn't get rid of the `eval` ...
;; one has to call:
(let* ((id "greeting")
       (message "Hello!")
       (the-html `((:p :id ,id) ,message)))
  (eval `(html ,the-html)))
Gwang-Jin Kim
  • 9,303
  • 17
  • 30