Clojure 任意位置的Enlive和tags
以下是Clojure 任意位置的Enlive和tags,clojure,enlive,Clojure,Enlive,以下是enlive 1.1.5(为了清晰起见添加了源代码格式/空白更改)的功能: 或 欢迎光临 根据,标签的ContentModel是文本,这意味着其中不允许HTML元素 Enlive解析HTML的部分可能只能处理有效的HTML,因此它不能很好地处理标记中的标记 你有几个选择 可以只设置标记的内容,而不是完全替换它,如下所示: (html/sniptest "<html><head><title>Placeholder</title></he
enlive 1.1.5
(为了清晰起见添加了源代码格式/空白更改)的功能:
或
欢迎光临
根据,标签的ContentModel是文本,这意味着其中不允许HTML元素
Enlive解析HTML的部分可能只能处理有效的HTML,因此它不能很好地处理
标记中的
标记
你有几个选择
可以只设置
标记的内容,而不是完全替换它,如下所示:
(html/sniptest "<html><head><title>Placeholder</title></head></html>"
[:title] (html/content "foo"))
;; => <title>foo</title>
编辑
我知道你说过你想避免${vars}
,但在这种情况下,他们恰好做了你想要的事情
(html/sniptest "<html><head><title>${my-site} - ${article-name}</title></head></html>"
[:title] (html/transform-content
(html/replace-vars
{:article-name "Using Enlive for good and evil"
:my-site "Clojure Weekly"})))
;; => <title>Clojure Weekly - Using Enlive for good and evil</title>
(html/sniptest“${my site}-${article name}”
[:title](html/转换内容)
(html/replace-vars)
{:文章名称“善恶用英语”
:我的网站“Clojure周刊”})
;; => Clojure周刊-使用Enlive表达善恶
你能澄清一下“在HTML源代码中写一个固定前缀,这样我的clojure代码就不会从我的最终内容中饱和”是什么意思吗?除非我误解了你想做什么,你能不能用(…“…”[:title](HTML/content“f”)
来设置标题的内容,而不是(…”[:title](HTML/content“f”)
?@DanielNeal:例如,一个在每个页面上都保持不变的站点标题,再加上一个通过clojure生成的动态部分,这将完全取代span元素。非常好。一旦我理解了规范将标题内容定义为文本节点,enlive就不解析它了。另外,我喜欢append
transformer,它已经足够好了:)
<p>Welcome, <span id="visitor-ip" /></p>
(html/sniptest "<html><head><title>Placeholder</title></head></html>"
[:title] (html/content "foo"))
;; => <title>foo</title>
(html/sniptest "<html><head><title>Some Title</title></head></html>"
[:title] (html/append " - sub page"))
;; => <title>Some Title - sub page</title>
(html/sniptest "<html><head><title>${my-site} - ${article-name}</title></head></html>"
[:title] (html/transform-content
(html/replace-vars
{:article-name "Using Enlive for good and evil"
:my-site "Clojure Weekly"})))
;; => <title>Clojure Weekly - Using Enlive for good and evil</title>