【问题标题】:cl-who and formatcl-who 和格式
【发布时间】:2012-07-03 15:03:57
【问题描述】:

我正在尝试使用 cl-who 生成以下 html 代码:

<html>
<body>
<div id="cnt_1"></div>
<div id="cnt_2"></div>
<div id="cnt_3"></div>
</body>
</html>

这是我认为可行的代码:

(with-html-output-to-string (*standard-output* nil)
 (:html
  (:body
   (do ((cnt 1 (+ cnt 1)))
       ((> cnt 3))
     (htm (:div :id (format t "cnt_~A" cnt)))))))

但我得到以下输出:

<html><body><divcnt_1></div><divcnt_2></div><divcnt_3></div></body></html>

似乎 :id 不适用于函数调用。这是否意味着我不能在 cl-who 中使用格式?我应该改用什么?

【问题讨论】:

    标签: lisp common-lisp sbcl hunchentoot cl-who


    【解决方案1】:

    那是因为您不想直接在流中写入。

    CL-USER> (with-html-output-to-string (s) (:div :id "test"))
    "<div id='test'></div>"
    
    CL-USER> (with-html-output-to-string (s)
               (:html
                (:body
                 (do ((cnt 1 (+ cnt 1)))
                     ((> cnt 3))
                   (htm (:div :id (format nil "cnt_~A" cnt)))))))
    
    "<html><body><div id='cnt_1'></div><div id='cnt_2'></div><div id='cnt_3'></div></body></html>"
    

    顺便说一句,如果您想直接在流中写入,请使用 CL-WHO:FMT。

    【讨论】:

    • FMT 作用于语法的内容部分,而不是属性值部分。
    • @Xach:通过工作,我想你的意思是它做你所期望的,因为它就像操作的 FORMAT 一样工作(写入当前流)。
    猜你喜欢
    • 2011-06-07
    • 2011-04-17
    • 2018-06-03
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多