是否可以使用enlive选择器检索原始HTML (及其怪癖和格式)?
(def data "<div class=\"foo\"><p>some text <br> some more text</p></div>")
(apply str
(enlive/emit* (enlive/select (enlive/html-snippet data)
[:.foo :> enlive/any-node])))
=> "<p>some text <br /> some more text</p>"在本例中,enlive将<br>标记转换为自结束标记,这与原始输入片段不同。
我怀疑enlive正在将其转换为一个类似hiccup的标签列表,因此原始信息不幸地丢失了。
发布于 2015-02-04 17:05:58
您的怀疑是正确的,在为HTML提供一致的抽象时,enlive会消耗这些信息。我不认为这是它设计提供的一个功能。
发布于 2015-02-06 00:09:36
虽然这可能只是切线相关,但如果使用“追加”,则可以保留否则将被net.cgrand.enlive-html/html-resource抛出的信息(例如注释)。
https://github.com/cgrand/enlive/wiki/Table-and-Layout-Tutorial%2C-Part-3%3A-Simple-Transformations
<div id="wrapper">
<!--body-->
</div>
jcrit.server=> (pprint
(transform layout [:#wrapper]
(append page-content)))
({:tag :html,
{:tag :div,
:attrs {:id "wrapper"},
:content
("\n "
{:type :comment, :data "body"} ; <<== Still there.
"\n "
{:tag :p, :content ("Hi, mom!")})}
"\n")}
"\n\n")})https://stackoverflow.com/questions/28323170
复制相似问题