On Sunday, August 16, 2015 at 12:04:23 PM UTC+8, Khalid Jebbari wrote:
> I know that Enlive does this internally, it uses JSoup from Java to convert
> to plain Clojure data structure. Not sure it exposes this functionality
> directly though.
Well that's a Clojure solution, not Clojurescript. Fortunately its such a
powerful language that I can usually get most of what I want with a single
function
(defn dom2edn [element]
(if (.-tagName element)
(let [
a (-> element .-tagName .toLowerCase keyword)
b (into {} (map (fn [[a b]] [(keyword a) b]) (js->clj (attributes
element))))
children (filter identity (map dom2edn (array-seq (.-childNodes
element))))
]
(if (not-empty children)
[a b children]
[a b]))
(if (.-textContent element)
(let [
trimmed (-> element .-textContent .trim)
]
(if (not-empty trimmed) trimmed)))))
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.