summaryrefslogtreecommitdiff
path: root/src/dompa/nodes.cljc
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2026-01-10 15:26:52 +0200
committerAsko Nõmm <asko@nmm.ee>2026-01-10 15:26:52 +0200
commit3d18750f03a50e87816cfa234f866cf4cc8f05e9 (patch)
tree440f3160ff09be973dd169b01f2d56bdfc717e6e /src/dompa/nodes.cljc
parent0863ef2e5c63f081375098c3c06c4ea21cf49e91 (diff)
Fix HTML rendering to handle nil values without removing sibling elements; add tests for nil handling in node hierarchy (#15)
Diffstat (limited to 'src/dompa/nodes.cljc')
-rw-r--r--src/dompa/nodes.cljc13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/dompa/nodes.cljc b/src/dompa/nodes.cljc
index eef65d3..e717690 100644
--- a/src/dompa/nodes.cljc
+++ b/src/dompa/nodes.cljc
@@ -38,7 +38,7 @@
(let [value (nodes->html-fn (-> node :node/children))]
(str html "<" node-name node-attrs ">" value "</" node-name ">"))))
- :else "")))
+ :else html)))
(defn traverse
"Recursively traverses given tree of `nodes` with a `traverser-fn`
@@ -149,7 +149,10 @@
(defn- nodes-from-opt
[opt]
- (cond (map? opt)
+ (cond (nil? opt)
+ nil
+
+ (map? opt)
opt
(empty-seq? opt)
@@ -157,7 +160,7 @@
(list-of-many? opt)
{:node/name :<>
- :node/children opt}
+ :node/children (remove nil? opt)}
(list-of-one? opt)
(first opt)
@@ -176,7 +179,9 @@
children-opts (if attrs? (drop 2 opts) (rest opts))
children-nodes (->> children-opts
(map nodes-from-opt)
- flatten)]
+ flatten
+ (remove nil?)
+ vec)]
(cond-> {:node/name first-opt}
attrs? (assoc :node/attrs attrs)
(seq children-nodes) (assoc :node/children children-nodes))))