Given that hiccup.core is deprecated, are there better/other ways to alter an HTML string as hiccup than
(hiccup.core/html (-> body hickory.core/parse hickory.core/as-hiccup f))
?If it still works, I'd just keep using it.
I'd check if hiccup2.core/html does the job
It doesn't parse HTML.
Iām not sure what this has to do with hiccup.core vs hiccup2.core
The former is deprecated and the latter is suggested to be used instead. But the latter doesn't have all the features of the former. Namely, parsing.
Since when did hiccup have an HTML parser?
Oh, oops. Just woke up. :)
1. hiccup.core is deprecated! 2. hiccup2.core doesn't roundtrip nicely with hickory.core/parse and as-hiccup any more, as it hiccup2's raw string behavior is to escape the HTML. My question was motivated by the fact that html string -> hiccup -> hiccup transformer -> hiccup -> string seems like a reasonable thing to want to do.
Enlive is good at this sort of thing - the parsing, the transformation, and the output- but it uses clojure.xml format, not hiccup, for the working structure. (and masterful use of zippers for modification)
Or just use hickory.core/as-hiccup2. There might be such a thing and if not, you could contribute it
The addition of escaping to hiccup was such a good thing that it seems reasonable the adapters-to-hiccup would happily cooperate
You can unescape HTML with hiccup2, just be explicit about it
I would provide the link but on phone
I can provide, i have computer
hiccup2.core/html
[options & content]
Macro
Added in 2.0
Render Clojure data structures to a compiled representation of HTML. To turn
the representation into a string, use clojure.core/str. Strings inside the
macro are automatically HTML-escaped. To insert a string without it being
escaped, use the raw function.
A literal option map may be specified as the first argument. It accepts two
keys that control how the HTML is outputted:
:mode
: One of :html, :xhtml, :xml or :sgml (defaults to :xhtml).
Controls how tags are rendered.
:escape-strings?
: True if strings should be escaped (defaults to true).
hiccup2.core/html is defined in
hiccup2/core.clj.Use the raw function
Or escape strings false
This did the trick:
(defn alter-response-hiccup [{:as response :keys [body]} f]
(assoc response :body (str (hiccup2.core/html {:escape-strings? false}
(-> body hickory.core/parse hickory.core/as-hiccup f)))))
Thank you all! š