Skip to content

Commit 60e6cdf

Browse files
committed
DXML-47 DXML-54 implement cdata and comment nodes for cljs
1 parent 7947b16 commit 60e6cdf

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/clojure/clojure/data/xml/js/dom.cljs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
(def NamedNodeMap (type (.-attributes (element :e))))
8080
(def NodeList (type (node-list [])))
8181
(def Attr (type (aget (.-attributes (element :e {:a "1"})) 0)))
82+
(def CData (type (cdata "")))
83+
(def Comment (type (xml-comment "")))
8284

8385
;; ## Coercions
8486

@@ -89,7 +91,11 @@
8991
[el]
9092
(cond
9193
(string? el) (text-node el)
94+
(instance? node/CData el) (cdata (:content el))
95+
(instance? node/Comment el) (xml-comment (:content el))
9296
(instance? Element el) el
97+
(instance? CData el) el
98+
(instance? Comment el) el
9399
;; stupid xmldom, (some? (.-item el))
94100
#_(instance? NodeList el)
95101
(some? (.-item el)) el
@@ -141,6 +147,10 @@
141147
"Coerce xml elements to element maps / content vectors"
142148
[el]
143149
(cond
150+
(instance? Comment el)
151+
(node/xml-comment (.-data el))
152+
(instance? CData el)
153+
(node/cdata (.-data el))
144154
(instance? Text el)
145155
(.-nodeValue el)
146156
(instance? Element el)

src/test/clojurescript/clojure/data/xml/test_cljs_basic.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
(are [dxml xml] (do (is (= dxml (xml/parse-str xml)))
1919
(is (= dxml (xml/parse-str (xml/emit-str dxml)))))
2020
(xml/element :foo) "<foo/>"
21-
(xml/element :xmlns.DAV%3A/foo) "<foo xmlns=\"DAV:\"/>"))
21+
(xml/element :xmlns.DAV%3A/foo) "<foo xmlns=\"DAV:\"/>"
22+
(xml/element :foo {} (xml/cdata "<foo")) "<foo><![CDATA[<foo]]></foo>"
23+
(xml/element :foo {} (xml/xml-comment " bar> ")) "<foo><!-- bar> --></foo>"))
2224

2325
(deftest printing
2426
(are [node ps] (is (= ps (pr-str node)))

0 commit comments

Comments
 (0)