Fix: extra empty line if SCHEDULED and DEADLINE exist

Fix https://github.com/logseq/logseq/issues/2506
This issue was also mentioned in
https://discuss.logseq.com/t/formatting-of-scheduled-items/1756/2

This PR offers an in-elegant way to remove the break_line element
following a timestamp element. I suppose this should be resolved in the
mldoc side. Anyway, this PR can be treated as a solution.
This commit is contained in:
leizhe
2021-09-19 11:04:41 +09:00
committed by Tienson Qin
parent 2df02a2dd5
commit 0774e2b74a

View File

@@ -739,6 +739,22 @@
(and (= typ "Paragraph")
(every? #(= % ["Break_Line"]) break-lines)))
(defn trim-paragraph-special-break-lines
[[typ paras]]
(println typ paras)
(when (= typ "Paragraph")
(let [indexed-paras (map-indexed vector paras)
ast [typ (->> (filter
#(let [[index value] %]
(not (and (> index 0)
(= value ["Break_Line"])
(contains? #{"Timestamp" "Macro"}
(first (nth paras (dec index)))))))
indexed-paras)
(map #(last %)))]]
ast)))
(defn trim-break-lines!
[ast]
(drop-while break-line-paragraph? ast))
(drop-while break-line-paragraph?
(map trim-paragraph-special-break-lines ast)))