summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAsko Nõmm <asko@nmm.ee>2026-01-10 15:30:09 +0200
committerGitHub <noreply@github.com>2026-01-10 15:30:09 +0200
commit94f5f3c21f8ad352e149b59ce3a5fa3ae98acb91 (patch)
tree440f3160ff09be973dd169b01f2d56bdfc717e6e /src
parent0863ef2e5c63f081375098c3c06c4ea21cf49e91 (diff)
parent3d18750f03a50e87816cfa234f866cf4cc8f05e9 (diff)
Merge pull request #16 from askonomm/15-ending-nils-remove-the-entire-hierarchy-at-its-levelv1.2.2
Fix HTML rendering to handle nil values without removing sibling elements
Diffstat (limited to 'src')
-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))))