diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-09-11 23:05:47 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-09-11 23:05:47 +0300 |
| commit | c9fb6f1c80a83f9e8ea88f7db3caedae57985fd7 (patch) | |
| tree | 61e8453a0463919d51805b045ee6045cc6e8aba4 /src/dompa/core.clj | |
| parent | 0c55f6d39bb83514f6b85f5da02214a78f2b1a13 (diff) | |
Getting there
Diffstat (limited to 'src/dompa/core.clj')
| -rw-r--r-- | src/dompa/core.clj | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/dompa/core.clj b/src/dompa/core.clj index 79d0c08..4891c46 100644 --- a/src/dompa/core.clj +++ b/src/dompa/core.clj @@ -7,20 +7,26 @@ (->> (html->coordinates html) (coordinates->nodes html))) +(def default-void-nodes + #{:img}) + +(defn- node->html + [{:keys [name content void-node?]}] + (if void-node? + (str "<" name ">") + (str "<" name ">" content "</" name ">"))) + (defn nodes->html ([nodes] - (nodes->html nodes {:void-nodes #{:img}})) + (nodes->html nodes {:void-nodes default-void-nodes})) ([nodes {:keys [void-nodes]}] (reduce (fn [html node] - (cond - (= (-> node :name) :dompa/text) + (if (= (-> node :name) :dompa/text) (str html (-> node :value)) - - :else - (let [node-name (-> node :name name) - node-child-html (nodes->html (-> node :children))] - (str html "<" node-name ">" node-child-html "</" node-name ">")))) + (node->html {:name (-> node :name name) + :content (nodes->html (-> node :children)) + :void-node? (contains? void-nodes (-> node :name))}))) "" nodes))) |
