How can I parse string into Hiccup?
Asked Answered
K

1

6

How can I parse a string of Hiccup into a Hiccup node?

For example, "[:b 'hello world']" into [:b "hello world"]

Karonkaross answered 21/3, 2015 at 3:51 Comment(0)
E
4

Use reader to convert string to data structures:

user=> (clojure.edn/read-string "[:b 'hello world']")
[:b 'hello world']

You should use " to denote string:

user=> (clojure.edn/read-string "[:b \"hello world\"]")
[:b "hello world"]
Extortion answered 21/3, 2015 at 20:13 Comment(1)
Thanks! For those using Clojurescript you'll want [cljs.reader]Karonkaross

© 2022 - 2024 — McMap. All rights reserved.