Convert flat headings to vector of trees

This commit is contained in:
Tienson Qin
2020-06-09 20:57:58 +08:00
parent 141a9a7286
commit d1244309a1
10 changed files with 184 additions and 189 deletions

View File

@@ -112,30 +112,6 @@
heading)))
headings))
(defn ->nested-headings [col]
(loop [coll (rest col)
children []
result [(first col)]]
(cond
(empty? coll)
result
(<= (:heading/level (first coll))
(:heading/level (last result)))
(recur
(rest coll)
[]
(let [last-element (assoc (last result) :heading/children children)]
(-> (vec (drop-last result))
(conj last-element (first coll)))))
(> (:heading/level (first coll))
(:heading/level (last result)))
(recur
(rest coll)
(->nested-headings (conj children (first coll)))
result))))
(defn extract-headings
[blocks last-pos]
(loop [headings []