It worked to solve my particular problem, but now I've been playing with this in your particular context and it doesn't.
(require '[net.cgrand.enlive-html :as h])
(require '[net.cgrand.jsoup :as jsoup])
(h/set-ns-parser! jsoup/parser)
; => {:net.cgrand.enlive-html/options {:parser #<jsoup$parser net.cgrand.jsoup$parser@24e1fb6c>}}
(h/html-snippet "<pre><p>Test</p></pre>")
; => ({:tag :body, :attrs nil, :content ({:tag :pre, :attrs nil, :content nil} {:tag :p, :attrs nil, :content ("Test")})})
That was not the expected result if jsoup is used. Looking at the source code for html-snippet, I see that that it calls to html-resource, and this gets the parser to use from *options*, so... I added a (println "*options*: " *options*) to check that *options* contains the configured parser, however what's printed is...
*options*: {:parser #<tagsoup$parser net.cgrand.tagsoup$parser@79b0edb2>}
Looking at Enlive source code again, I see that when the parser is configure with (h/set-ns-parser! jsoup/parser), the value of *options* is not changed. The only place where *options* is changed is in the with-options macro. I don't understand why set-ns-parser! doesn't change *options*, but anyway, let's try with with-options...
(h/with-options {:parser jsoup/parser}
(h/html-snippet "<pre><p>Test</p></pre>"))
The result is...
java.lang.IllegalArgumentException: No matching method found: parse (NO_SOURCE_FILE:0)
Looking at the html-snippet definition, I see that it calls html-resource with a java.io.StringReader., and html-resource in turn calls the multimethod get-resource (with the reader and the parser from *options*). When passed a reader (java.io.Reader), get-resource simply calls the parser (named 'loader' here) with that reader. Looking at the source code for the configured parser, jsoup/parser, I see this is a function (I find strange that this function is named 'parser'... wouldn't be 'parse' a better name? anyway, I'm digressing) that calls Java's org.jsoup.Jsoup.parse() method. Looking at the Jsoup docs (
http://jsoup.org/apidocs/org/jsoup/Jsoup.html ) it seems there's no any parse() method that accepts a reader, and that seems to be the ultimate cause of the java.lang.IllegalArgumentException .
As far as I understand, this is a problem that has to be solved in the Enlive code. I would like to provide a pull-request with a solution, but I don't fully understand how parser configuration is supposed to work, or how to work around the fact that Jsoup's parse() doesn't accept readers (I tried modifying Enlive's html-snippet to call html-resouce with a ByteArrayInputStream, which is accepted by Jsoup's parse(), instead of a StringReader, but I didn't get the expected result). At least I hope my investigation can be useful for someone that maybe could provide a solution :)
Cheers!