This commit is contained in:
2026-03-10 13:59:00 -06:00
parent cbfa42bc73
commit e20dcf591d

View File

@@ -231,15 +231,25 @@
(recur next-loc-read next-loc-write))))
wa-loc))
(defn separated-by-explicit-paragraph-break? [e e]
(= (-> e :position :end :line inc)
(-> e :position :start :line inc)))
(defn separated-by-explicit-paragraph-break?
"Returh truthy if each successive pair of elements is separated by
at least one explicit paragraph break; i.e. a blank line."
[& elements]
(match elements
[e e & es]
(and (< (-> e :position :end :line)
(-> e :position :start :line))
(recur es))
:else true))
(defn swallow [predator prey]
(defn swallow
([predator prey]
(assert (greater-element? predator))
(-> predator
(update :children #(conj % prey))
(assoc-in [:position :end] (-> prey :position :end))))
([predator prey & more-prey]
(reduce swallow predator (cons prey more-prey))))
(comment
(-> [1 2 3 4]
@@ -255,13 +265,20 @@
(loop [acc []
cs (vec children)]
(match cs
[(para :guard #(of-type? % "paragraph"))
([(para :guard #(of-type? % "paragraph"))
(tex :guard #(of-type? % "latex-environment"))
(para :guard #(of-type? % "paragraph"))
& rest]
:guard #(apply separated-by-explicit-paragraph-break? %))
(recur (conj acc (swallow para tex para)) rest)
([(para :guard #(of-type? % "paragraph"))
(tex :guard #(of-type? % "latex-environment"))
& rest]
:guard #(apply separated-by-explicit-paragraph-break? %))
(recur (conj acc (swallow para tex)) rest)
[] acc
[c & rest]
(recur (conj acc c) rest))))
(recur (conj acc c) rest)
[] acc)))
doc)]
@r))