clojureenlive

Enlive - extract original HTML


Is it possible to retrieve the original HTML (with its quirks and formatting) using enlive selectors?

(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>"

In this example, enlive has transformed the <br> tag into a self-closing tag, unlike the original input snippet.

I suspect that enlive is transforming it into a hiccup-like list of tags, such that the original information is unfortunately lost.


Solution

  • Your suspicion is correct, enlive consumes this information in it's efforts to provide a consistent abstraction over the HTML. I don't think this was a feature it was designed to offer.