开发者

How Can I Output an HTML Comment in Compojure/Hiccup?

I'd like my program to output the following HTML:

&开发者_StackOverflow中文版lt;!--[if lt IE 8]><link rel="stylesheet" href="../blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->

Is there a way to output html comment literals with Hiccup?


Just insert them. Maybe this is a little bit cheating, but it works...

user=> (html
         [:html
          [:head
           "<!--[if lt IE 8]>"
           [:link {:rel  "stylesheet"
                   :href "../blueprint/ie.css"
                   :type "text/css"
                   :media "screen,projection"}]
           "<![endif]-->"]])
<html><head><!--[if lt IE 8]><link href=\"../blueprint/ie.css\" media=\"screen,projection\" rel=\"stylesheet\" type=\"text/css\" /><![endif]--></head></html>


You got me curious, so I re-read the code: there's no explicit comment function - you would have to pass that as a string literal. But you could do something like:

(defn comment
  "Wrap the supplied HTML in a comment"
  [html]
  (str "<!--" html "-->"))

if you really needed the function (although that's pretty simplistic). You could always add the IE if statement as an optional parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜