From 41c1d9eadd3a5cb0a804390edca592c197f49d33 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sun, 24 Aug 2025 19:03:27 +0300 Subject: Initial commit --- src/dompa/nodes.clj | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/dompa/nodes.clj (limited to 'src/dompa/nodes.clj') 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))))) -- cgit v1.2.3