Skip to content

Instantly share code, notes, and snippets.

@raek
Created October 18, 2010 20:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/633049 to your computer and use it in GitHub Desktop.
Save raek/633049 to your computer and use it in GitHub Desktop.
(defn enlive->hiccup [node]
(if-not (map? node)
node
(let [{:keys [tag attrs content]} node
children (map enlive->hiccup content)]
(if (empty? attrs)
(vec (cons tag children))
(vec (cons tag (cons attrs children)))))))
(defn hiccup->enlive [node]
(if-not (vector? node)
node
(let [[tag & children] node
attrs (when (map? (first children))
(first children))
children (if attrs
(rest children)
children)]
{:tag tag
:attrs attrs
:content (map hiccup->enlive children)})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment