mirror of https://github.com/logseq/logseq
fix(diff-merge): multi-line blocks format
parent
fb4e23bb95
commit
fd493bde0d
|
@ -91,25 +91,37 @@
|
||||||
(reverse headings))))))))
|
(reverse headings))))))))
|
||||||
|
|
||||||
|
|
||||||
(defn- prepend-lines
|
(defn- prepend-block-lines
|
||||||
"prepend prefix to every lines of content"
|
"prepend prefix to every lines of content except first"
|
||||||
[prefix content]
|
[fisrt-prefix prefix content]
|
||||||
(->> content
|
(let [lines (string/split-lines content)]
|
||||||
(string/split-lines)
|
(if (<= (count lines) 1)
|
||||||
|
(str fisrt-prefix content)
|
||||||
|
(str (str fisrt-prefix (first lines))
|
||||||
|
"\n"
|
||||||
|
(->> (rest lines)
|
||||||
(map (fn [line] (str prefix line)))
|
(map (fn [line] (str prefix line)))
|
||||||
(string/join "\n")))
|
(string/join "\n")))
|
||||||
|
)))
|
||||||
|
|
||||||
(defn- rebuild-content
|
(defn- rebuild-content
|
||||||
"translate [[[op block]]] to merged content"
|
"translate [[[op block]]] to merged content"
|
||||||
[_base-diffblocks diffs format]
|
[_base-diffblocks diffs format]
|
||||||
;; [[[0 {:body "attrib:: xxx", :level 1, :uuid nil}] ...] ...]
|
;; [[[0 {:body "attrib:: xxx", :level 1, :uuid nil}] ...] ...]
|
||||||
(let [level-prefix-fn (fn [level]
|
(let [level-prefix-fn (fn [level]
|
||||||
(when (and (= format :markdown) (not= level 1))
|
(when (= format :markdown)
|
||||||
(apply str (repeat (dec level) "\t"))))
|
(str (apply str (repeat (dec level) "\t"))
|
||||||
|
" ")))
|
||||||
|
heading-prefix-fn (fn [level]
|
||||||
|
(when (= format :markdown)
|
||||||
|
(str (apply str (repeat (dec level) "\t"))
|
||||||
|
"- ")))
|
||||||
ops-fn (fn [ops]
|
ops-fn (fn [ops]
|
||||||
(map (fn [[op {:keys [body level]}]]
|
(map (fn [[op {:keys [body level]}]]
|
||||||
(when (or (= op 0) (= op 1)) ;; equal or insert
|
(when (or (= op 0) (= op 1)) ;; equal or insert
|
||||||
(str (level-prefix-fn level) "-" (prepend-lines " " body))))
|
(prepend-block-lines (heading-prefix-fn level)
|
||||||
|
(level-prefix-fn level)
|
||||||
|
body)))
|
||||||
ops))]
|
ops))]
|
||||||
(->> diffs
|
(->> diffs
|
||||||
(mapcat ops-fn)
|
(mapcat ops-fn)
|
||||||
|
|
Loading…
Reference in New Issue