0

我正在通过 Adam Tornhill 的 Lisp For The Web 工作,我一直在生成一个包含 li 元素的 html 页面。

(with-html-output (*standard-output* nil :prologue t :indent t)
   (htm
       (:li (:a :href "Link" "Vote!")
        )))

当我编译它时,以下输出被打印到 REPL

(with-html-output (*standard-output* nil :prologue t :indent t)
   (htm 
       (:li (:a :href "Link" "Vote!")
        )))
 <!DOCTYPE html>

<li>
  <a href='Link'>Vote!
  </a>
</li>
"
<li>
  <a href='Link'>Vote!
  </a>     
</li>"   

通常不添加输出末尾的字符串,并且包含此字符串的站点不会在 hunchentoot 中呈现。在 :li 周围添加 :ol 并没有帮助,我想保持示例最小化。

书中的代码作为参考:

(define-easy-handler (retro-games :uri "/retro-games") () 
  (standard-page (:title "Top Retro Games") 
   (:h1 "Vote on your all time favourite retro games!") 
   (:p "Missing a game? Make it available for votes " (:a :href "new-game" "here")) 
   (:h2 "Current stand") 
   (:div :id "chart" ; Used for CSS styling of the links. 
     (:ol 
 (dolist (game (games)) 
  (htm   
   (:li (:a :href (format nil "vote?name=~a" (escape-string ; avoid injection attacks 
                                                 (name game))) "Vote!") 
         (fmt "~A with ~d votes" (name game) (votes game)))))))))
4

1 回答 1

2

您首先看到的是表单在评估时打印的内容。*standard-output*之后看到的字符串是表单的结果,由 REPL 打印。由于您的 Hunchentoot 处理程序只对输出流的内容感兴趣,因此结果并不重要。

要简单地将结果作为字符串获取,您可以使用with-html-output-to-string

(with-html-output-to-string (str nil :prologue t :indent t)
  (htm 
   (:li (:a :href "Link" "Vote!"))))

另一方面,要抑制结果字符串并只看到写出的文档,您可以执行以下操作:

(progn
  (with-html-output (*standard-output* nil :prologue t :indent t)
    (htm 
     (:li (:a :href "Link" "Vote!"))))
  (values))
于 2014-04-30T05:32:30.053 回答