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)))) (recur next-loc-read next-loc-write))))
wa-loc)) wa-loc))
(defn separated-by-explicit-paragraph-break? [e e] (defn separated-by-explicit-paragraph-break?
(= (-> e :position :end :line inc) "Returh truthy if each successive pair of elements is separated by
(-> e :position :start :line inc))) 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
(assert (greater-element? predator)) ([predator prey]
(-> predator (assert (greater-element? predator))
(update :children #(conj % prey)) (-> predator
(assoc-in [:position :end] (-> prey :position :end)))) (update :children #(conj % prey))
(assoc-in [:position :end] (-> prey :position :end))))
([predator prey & more-prey]
(reduce swallow predator (cons prey more-prey))))
(comment (comment
(-> [1 2 3 4] (-> [1 2 3 4]
@@ -255,13 +265,20 @@
(loop [acc [] (loop [acc []
cs (vec children)] cs (vec children)]
(match cs (match cs
[(para :guard #(of-type? % "paragraph")) ([(para :guard #(of-type? % "paragraph"))
(tex :guard #(of-type? % "latex-environment")) (tex :guard #(of-type? % "latex-environment"))
& rest] (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) (recur (conj acc (swallow para tex)) rest)
[] acc
[c & rest] [c & rest]
(recur (conj acc c) rest)))) (recur (conj acc c) rest)
[] acc)))
doc)] doc)]
@r)) @r))