(line->segments line tags-for-line escape?)
Splits a line into segments where tags are supposed to appear.
Spec
(clojure.spec.alpha/fspec
:args
(clojure.spec.alpha/cat
:line
clojure.core/string?
:tags-for-line
(clojure.spec.alpha/nilable :tag-soup.core/tags-for-line)
:escape?
clojure.core/boolean?)
:ret
(clojure.spec.alpha/coll-of clojure.core/string?)
:fn
nil)
Source
(defn line->segments
"Splits a line into segments where tags are supposed to appear."
[line tags-for-line escape?]
(let [columns (set (map :column tags-for-line))
escape-html-char (if escape? escape-html-char identity)]
(loop [i 0
segments (transient [])
current-segment (transient [])]
(if-let [c (some-> line (get i) escape-html-char)]
(if (contains? columns (inc i))
(recur (inc i)
(conj! segments (persistent! current-segment))
(transient [c]))
(recur (inc i)
segments
(conj! current-segment c)))
(->> (persistent! current-segment)
(conj! segments)
persistent!
(map str/join))))))