diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-08-24 19:03:27 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-08-24 19:03:27 +0300 |
| commit | 41c1d9eadd3a5cb0a804390edca592c197f49d33 (patch) | |
| tree | 6d760ef1e6f3ee4dc80f97a7de0ccfa7b02feed3 /src/dompa/nodes.clj | |
Initial commit
Diffstat (limited to 'src/dompa/nodes.clj')
| -rw-r--r-- | src/dompa/nodes.clj | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/dompa/nodes.clj b/src/dompa/nodes.clj new file mode 100644 index 0000000..9b30be3 --- /dev/null +++ b/src/dompa/nodes.clj @@ -0,0 +1,30 @@ +(ns dompa.nodes + (:require [clojure.string :as str] + [dompa.coordinates :as coordinates])) + +(defn- html->node-name [html] + (if (str/starts-with? html "<") + (-> html + (str/split #"[\s\>]") + first + (str/replace #"[\<\>\/]" "") + keyword) + :text-node)) + +(defn- html->node-attrs [html]) + + + +(defn coordinates->nodes + [html coordinates] + (when (seq coordinates) + (let [sorted-coordinates (sort-by first coordinates) + [parent-from parent-to] (first sorted-coordinates) + children (coordinates/children sorted-coordinates [parent-from parent-to]) + remaining (coordinates/without-children sorted-coordinates [parent-from parent-to]) + node-html (subs html parent-from (inc parent-to))] + (cons {:value (subs html parent-from (inc parent-to)) + :name (html->node-name node-html) + :attrs (html->node-attrs node-html) + :children (coordinates->nodes html children)} + (coordinates->nodes html remaining))))) |
