From 3a8a9cf2bc4d775153ce5fd0a00645c49384c46e Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sun, 19 Oct 2025 12:56:10 +0300 Subject: Reduce complex conditionals inside the `compose-reducer-fn`. --- src/dompa/coordinates.cljc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/dompa/coordinates.cljc') 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} -- cgit v1.2.3