1

Clojure 和 enlive 都很棒。在尝试了解 Enlive 的强大功能时,我尝试将两种转换应用于 html 页面。

HTML 页面有 2 个我想要转换的区域(div)。有问题的第一个 div 被克隆了约 16 次。有问题的第二个 div 被克隆了 5 次。原始 div(来自 html 文件)应该被覆盖或根本不出现。

Enlive 有惯用的方法

(apply str (enlive-html/emit* ze-contant-transferm))

这对于一次转换非常有效。

但是,我想对页面应用两个转换,所以我尝试了类似的方法:

(str
  (apply str (enlive-html/emit* ze-first-wan))
  (apply str (enlive-html/emit* ze-secand-wan)))

单独完成的转换完全按照我的意愿进行:它们会占用原始 HTML 并显示我用于填充信息的克隆。

但是,以这种方式一起完成,原始的 html 页面 div 被保留,所以我最终得到了原始 html 文件 div 以及我的克隆,并且这种行为不是 bueno。

请帮忙。

非常感谢。

4

1 回答 1

3

Enlive-htmldo-> 为此提供了功能。

(defn do->
 "Chains (composes) several transformations. Applies functions from left to right."
 [& fns]
  #(reduce (fn [nodes f] (flatmap f nodes)) (as-nodes %) fns))

你可以使用这样的东西:

 (apply str (enlive-html/emit* (enlive-html/do-> ze-first-wan ze-second-wan)))
于 2015-02-11T07:57:13.973 回答