diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-10-19 12:56:10 +0300 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-10-19 12:56:10 +0300 |
| commit | 3a8a9cf2bc4d775153ce5fd0a00645c49384c46e (patch) | |
| tree | fd8ff953fb78bd48401627b7fcbba561bd73226d /src | |
| parent | dd3f6324e701f6c643fb568b586dacd549c6c7db (diff) | |
Reduce complex conditionals inside the `compose-reducer-fn`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dompa/coordinates.cljc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/dompa/coordinates.cljc b/src/dompa/coordinates.cljc index 8cdcd7d..bba8b5c 100644 --- a/src/dompa/coordinates.cljc +++ b/src/dompa/coordinates.cljc @@ -1,6 +1,18 @@ (ns dompa.coordinates (:require [clojure.string :as str])) +(defn- text-ended-and-tag-begins? [char char-type] + (and (= :text char-type) + (= \< char))) + +(defn- text-ended-by-html-ending? [char-type total-char-count idx] + (and (= :text char-type) + (= (dec total-char-count) idx))) + +(defn- tag-starts? [char char-type] + (and (not= :text char-type) + (= \< char))) + (defn- compose-reducer-fn "Returns a reducer function with initial state of `total-char-count` integer." @@ -16,24 +28,21 @@ ; text ended, tag begins, which means we can ; record text node coordinates - (and (= :text char-type) - (= \< c)) + (text-ended-and-tag-begins? c char-type) {:char-type :tag :start-idx idx :coordinates (conj coordinates [start-idx (dec idx)])} ; text ended by HTML ending, record text node ; coordinates - (and (= :text char-type) - (= (dec total-char-count) idx)) + (text-ended-by-html-ending? char-type total-char-count idx) {:char-type nil :start-idx idx :coordinates (conj coordinates [start-idx idx])} ; otherwise don't record anything, just note ; the start of a tag - (and (not= :text char-type) - (= \< c)) + (tag-starts? c char-type) {:char-type :tag :start-idx idx :coordinates coordinates} |
