Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Created January 17, 2015 01:20
Show Gist options
  • Save AlexBaranosky/5167547ce97eb8b14375 to your computer and use it in GitHub Desktop.
Save AlexBaranosky/5167547ce97eb8b14375 to your computer and use it in GitHub Desktop.
;; Copied from:
;; https://github.com/davidsantiago/hickory/blob/6c02f7e5383549906855246358a15f3e0dcd3264/src/hickory/core.cljs#L69
;;
;; .. with one small modification commented inline. SEE: hickory/Text
;; Original modified line:
;; https://github.com/davidsantiago/hickory/blob/6c02f7e5383549906855246358a15f3e0dcd3264/src/hickory/core.cljs#L95
(extend-protocol hickory/HiccupRepresentable
object
(as-hiccup [this]
(condp = (aget this "nodeType")
hickory/Attribute
[(hickory-utils/lower-case-keyword (aget this "name"))
(aget this "value")]
hickory/Comment
(str "<!--" (aget this "data") "-->")
hickory/Document
(map hickory/as-hiccup (aget this "childNodes"))
hickory/DocumentType
(hickory/format-doctype this)
hickory/Element
(let [tag (hickory-utils/lower-case-keyword (aget this "tagName"))]
(into [] (concat [tag
(into {} (map hickory/as-hiccup (aget this "attributes")))]
(if (hickory-utils/unescapable-content tag)
(map #(aget % "wholeText") (aget this "childNodes"))
(map hickory/as-hiccup (aget this "childNodes"))))))
hickory/Text
(aget this "wholeText"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment