2

我正在尝试通过 hunchentoot 和 cl-who 构建个人网站,但在以下代码中出现语义错误:

(defun index ()
  (standart-page (:title "~apb")
                 (dolist (article (articles))
                   (cl-who:htm
                    (:ul
                     (:li (format nil "~a: ~a" (article-date article) (article-title article))))))))

“标准页面”是一个宏:

(defmacro standart-page ((&key title) &body body)   `(cl-who:with-html-output-to-string (*standart-output* nil :prologue t :indent t)
                               (:html :xmlns "http://www.w3.org/1999/xhtml"
                                      :xml\:lang "de"
                                      :lang "de"
                                      (:head
                                       (:title ,title)
                                       (:body
                                        (:div :id "wrapper"
                                              (:div :id "header"
                                                    (:h1 "~apb"))
                                              (:div :id "content"
                                                    ,@body)))))))

“(index)”的评估(在“(articles)”中有一篇测试文章返回:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='de' lang='de'>
  <head>
    <title>
      ~apb
    </title>
    <body>
      <div id='wrapper'>
        <div id='header'>
          <h1>
            ~apb
          </h1>
        </div>
        <div id='content'>
          <ul>
            <li>
            </li>
          </ul>
        </div>
      </div>
    </body>
  </head>
</html>

通过查看<li>..</li>标签,我想知道为什么没有输出。我认为格式功能有问题,但我不知道是什么。

4

3 回答 3

3

具体来说format,安德鲁的答案是正确的。一般来说,您可以使用str

CL-USER> (with-html-output-to-string (*standard-output*)
           (:p (str (format nil "~A" '<hello/>))))
"<p><HELLO/></p>"

请注意,在这种情况下,字符串不是 HTML 转义的(这fmt也适用)。如果你想要它,请esc改用:

CL-USER> (with-html-output-to-string (*standard-output*)
           (:p (esc (format nil "~A" '<hello/>))))
"<p>&lt;HELLO/&gt;</p>"

类似地,htm在退出 HTML 模式后使用它返回:

CL-USER> (with-html-output-to-string (*standard-output*)
           (:ul (loop for x from 1 to 3
                      do (htm (:li (str x))))))
"<ul><li>1</li><li>2</li><li>3</li></ul>"
于 2010-12-17T11:25:37.103 回答
2

一个明显的错误是您拼错了“标准”。因此,将流绑定到(sic) 不会像您预期*standart-output*的那样重新绑定。*standard-output*

于 2010-12-16T15:22:46.533 回答
1

查看 CL-WHO 网站上的使用示例,我认为您不能只使用返回字符串的格式。他们的所有示例都使用自定义输出函数(例如 fmt),这些函数似乎在后台写入动态变量。在 CL-WHO 生成的代码示例中,您可以将其视为宏扩展中的一行。 (format http-output-stream ....)

这可以解释为什么你没有得到任何输出,你只需要使用他们的自定义输出编写器而不是(format nil ..)你正在使用的。你可能想要类似的东西

(fmt "~a: ~a" (article-date article) (article-title article))

于 2010-12-16T12:43:32.043 回答