mirror of https://github.com/logseq/logseq
fix: parse-block preserve parent and left
parent
db4d8c8f47
commit
84fb245d8a
|
@ -501,55 +501,39 @@
|
||||||
[blocks parents' result]))]
|
[blocks parents' result]))]
|
||||||
(recur blocks parents result)))))
|
(recur blocks parents result)))))
|
||||||
|
|
||||||
|
;; TODO: remove meta, pos
|
||||||
(defn parse-block
|
(defn parse-block
|
||||||
([block format]
|
([block format]
|
||||||
(parse-block block format nil))
|
(parse-block block format nil))
|
||||||
([{:block/keys [uuid content meta file page pre-block?] :as block} format {:keys [with-id?]
|
([{:block/keys [uuid content meta file page pre-block? parent left] :as block}
|
||||||
|
format
|
||||||
|
{:keys [with-id?]
|
||||||
:or {with-id? true}}]
|
:or {with-id? true}}]
|
||||||
(when-not (string/blank? content)
|
(when-not (string/blank? content)
|
||||||
(let [ast (format/to-edn content format nil)
|
(let [ast (format/to-edn content format nil)
|
||||||
start-pos (:start-pos meta)
|
start-pos (:start-pos meta)
|
||||||
encoded-content (utf8/encode content)
|
encoded-content (utf8/encode content)
|
||||||
content-length (utf8/length encoded-content)
|
content-length (utf8/length encoded-content)
|
||||||
blocks (extract-blocks ast content with-id?)
|
new-block (first (extract-blocks ast content with-id?))
|
||||||
ref-pages-atom (atom [])
|
ref-pages-atom (atom [])
|
||||||
parent-ref-pages (->> (db/get-block-parent (state/get-current-repo) uuid)
|
parent-ref-pages (->> (db/get-block-parent (state/get-current-repo) uuid)
|
||||||
:block/path-refs
|
:block/path-refs
|
||||||
(map :db/id))
|
(map :db/id))
|
||||||
blocks (doall
|
block (let [{:block/keys [refs]} new-block
|
||||||
(map-indexed
|
ref-pages (filter :block/name refs)
|
||||||
(fn [idx {:block/keys [refs meta] :as block}]
|
|
||||||
(let [ref-pages (filter :block/name refs)
|
|
||||||
path-ref-pages (concat ref-pages parent-ref-pages)
|
path-ref-pages (concat ref-pages parent-ref-pages)
|
||||||
block (merge
|
block (merge
|
||||||
block
|
block
|
||||||
{:block/meta meta
|
new-block
|
||||||
:block/marker (get block :block/marker "nil")
|
{:block/path-refs path-ref-pages})]
|
||||||
:block/properties (get block :block/properties {})
|
|
||||||
:block/file file
|
|
||||||
:block/format format
|
|
||||||
:block/page page
|
|
||||||
:block/content (utf8/substring encoded-content
|
|
||||||
(:start-pos meta)
|
|
||||||
(:end-pos meta))
|
|
||||||
:block/path-refs path-ref-pages}
|
|
||||||
;; Preserve the original block id
|
|
||||||
(when (zero? idx)
|
|
||||||
{:block/uuid uuid})
|
|
||||||
(when (seq refs)
|
|
||||||
{:block/refs
|
|
||||||
(mapv
|
|
||||||
(fn [page]
|
|
||||||
(when (:block/name page)
|
|
||||||
(swap! ref-pages-atom conj page))
|
|
||||||
page)
|
|
||||||
refs)}))]
|
|
||||||
(-> block
|
(-> block
|
||||||
(assoc-in [:block/meta :start-pos] (+ (:start-pos meta) start-pos))
|
(assoc-in [:block/meta :start-pos] (+ (:start-pos meta) start-pos))
|
||||||
(assoc-in [:block/meta :end-pos] (+ (:end-pos meta) start-pos)))))
|
(assoc-in [:block/meta :end-pos] (+ (:end-pos meta) start-pos))))
|
||||||
blocks))
|
_ (doseq [page (:refs block)]
|
||||||
|
(when (:block/name page)
|
||||||
|
(swap! ref-pages-atom conj page)))
|
||||||
pages (vec (distinct @ref-pages-atom))]
|
pages (vec (distinct @ref-pages-atom))]
|
||||||
{:blocks blocks
|
{:blocks [(dissoc block :db/id)]
|
||||||
:pages pages
|
:pages pages
|
||||||
:start-pos start-pos
|
:start-pos start-pos
|
||||||
:end-pos (+ start-pos content-length)}))))
|
:end-pos (+ start-pos content-length)}))))
|
||||||
|
|
|
@ -66,9 +66,7 @@
|
||||||
[block]
|
[block]
|
||||||
(let [refs (if-let [refs (seq (:block/refs-with-children block))]
|
(let [refs (if-let [refs (seq (:block/refs-with-children block))]
|
||||||
refs
|
refs
|
||||||
(concat
|
(:block/refs block))]
|
||||||
(:block/refs block)
|
|
||||||
(:block/tags block)))]
|
|
||||||
(distinct refs)))
|
(distinct refs)))
|
||||||
|
|
||||||
(defn prepare-blocks
|
(defn prepare-blocks
|
||||||
|
|
|
@ -397,6 +397,7 @@
|
||||||
tx
|
tx
|
||||||
transact-option)
|
transact-option)
|
||||||
|
|
||||||
|
;; TODO: remove
|
||||||
(when (seq pages)
|
(when (seq pages)
|
||||||
(let [children-tx (mapcat #(rebuild-page-blocks-children repo %) pages)]
|
(let [children-tx (mapcat #(rebuild-page-blocks-children repo %) pages)]
|
||||||
(when (seq children-tx)
|
(when (seq children-tx)
|
||||||
|
|
Loading…
Reference in New Issue