Writing a transformation

52 views
Skip to first unread message

Juanjo Conti

unread,
Dec 3, 2015, 9:37:19 AM12/3/15
to Enlive
Hi there! I'm super new at enlive. I'm trying to write a transformation to convert a node of the form:

<div key=valuea-valueb><pre>text</pre></div>

to

<pre key=valueb>text</pre>

how can I do it?

Thanks in advance!

Carousel Apps Limited, registered in England & Wales with registered number 7689440 and registered office 20-22 Wenlock Road, London, N1 7GU, United Kingdom. Any communication sent by or on behalf of Carousel Apps or any of its subsidiary, holding or affiliated companies or entities is confidential and may be privileged or otherwise protected. If you receive it in error please inform us and then delete it from your system. You should not copy it or disclose its contents to anyone. Messages sent to and from Carousel Apps may be monitored to ensure compliance with our internal policies and to protect our business. Emails are not secure and cannot be guaranteed to be error free. Anyone who communicates with us by email is taken to accept these risks.

Christophe Grand

unread,
Dec 3, 2015, 9:40:58 AM12/3/15
to enlive-clj
Hi Juanjo,

Some more details required: is "valuea-" dropped? do you expect to have a single <pre> in this <div> or it may have siblings (including text/whitespace)?

Christophe

--
You received this message because you are subscribed to the Google Groups "Enlive" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enlive-clj+...@googlegroups.com.
To post to this group, send email to enliv...@googlegroups.com.
Visit this group at http://groups.google.com/group/enlive-clj.
For more options, visit https://groups.google.com/d/optout.



--
On Clojure http://clj-me.cgrand.net/
Clojure Programming http://clojurebook.com
Training, Consulting & Contracting http://lambdanext.eu/

Juanjo Conti

unread,
Dec 3, 2015, 9:53:12 AM12/3/15
to Enlive, chris...@cgrand.net
It will we only one pre per div.

Here is the real example. I want to convert this:

<div class="highlight highlight-source-clojure"><pre>(<span class="pl-k">def</span> <span class="pl-e">js-engine</span> (<span class="pl-en">atom</span> <span class="pl-c1">nil</span>))

(<span class="pl-en">reset!</span> js-engine (<span class="pl-en">prerenderer/run</span> {<span class="pl-c1">:path</span> <span class="pl-s"><span class="pl-pds">"</span>target/js/server-side.js<span class="pl-pds">"</span></span>})))</pre></div>

to this:

<pre class="lang:clojure decode:true ">(def js-engine (atom nil))

(reset! js-engine (prerenderer/run {:path "target/js/server-side.js"})))</pre>

(note there are also some spans to strip out)
Message has been deleted

Juanjo Conti

unread,
Dec 4, 2015, 2:31:16 PM12/4/15
to Enlive, chris...@cgrand.net
I'm doing it like this:

(defn get-content
[url] (html/at
(html/select (fetch-url url) [:article :> :*])
[:h1] nil ; strip h1 from content
[:p html/text-node] (fn [node] (newline-to-space node))
[:div :pre :span] html/unwrap
[:div :pre :code] html/unwrap
[:div.highlight] html/unwrap
[:pre] (html/add-class "lang:clojure" "decode:true")))

Any comments?
Reply all
Reply to author
Forward
0 new messages