clj-commons / hickory

HTML as data
Other
637 stars 52 forks source link

(as-hiccup (parse-fragment ...)) doesn't work in clojurescript with shadow-cljs #57

Closed jtlocsei closed 4 years ago

jtlocsei commented 4 years ago

Example:

(as-hiccup (parse-fragment "hello world"))

Results in error:

Error: No matching clause: 
    at eval (core.cljs:71)
    at Object.hickory$core$as_hiccup [as as_hiccup] (core.cljs:13)

Parse works OK, e.g.

(as-hiccup (parse "hello world"))
=> ([:html {} [:head {}] [:body {} "hello world"]])

And parse-fragment itself doesn't throw an error, it's only thrown when I call as-hiccup or as-hickory on the result of the parse.

(parse-fragment "hello world")
=> #object[NodeList [object NodeList]]

Here are some more results in case they help debug:

(parse "hello world")
=> #object[HTMLDocument [object HTMLDocument]]
(aget (parse "hello world") "body")
=> #object[HTMLBodyElement [object HTMLBodyElement]]
(aget (parse "hello world") "body" "childNodes")
=> #object[NodeList [object NodeList]]
(aget (parse "hello world") "body" "childNodes" "nodeType")
=> nil
jtlocsei commented 4 years ago

Also, in case it's relevant,

(exists? js/DOMParser)
=> true
jtlocsei commented 4 years ago

Sorry, ignore the above, I missed the bit in the readme about how you need to map as-hiccup onto the parsed fragment.

a fragment is parsed, but it cannot be directly used with as-hiccup (or as-hickory), it must have those functions called on each element in the list instead.