fix: can't paste headings

fixes https://github.com/logseq/db-test-cn/issues/7
This commit is contained in:
Tienson Qin
2024-08-08 20:28:11 +08:00
parent 4c2d6416ce
commit b4a887c026
4 changed files with 35 additions and 24 deletions

View File

@@ -19,20 +19,30 @@ and handles unexpected failure."
[blocks content format {:keys [page-name parse-block]}]
(let [repo (state/get-current-repo)]
(try
(gp-block/extract-blocks blocks content format
{:user-config (state/get-config)
:parse-block parse-block
:block-pattern (config/get-block-pattern format)
:db (db/get-db repo)
:date-formatter (state/get-date-formatter)
:page-name page-name
:db-graph-mode? (config/db-based-graph? repo)})
(catch :default e
(log/error :exception e)
(state/pub-event! [:capture-error {:error e
:payload {:type "Extract-blocks"}}])
(notification/show! "An unexpected error occurred during block extraction." :error)
[]))))
(let [blocks (gp-block/extract-blocks blocks content format
{:user-config (state/get-config)
:parse-block parse-block
:block-pattern (config/get-block-pattern format)
:db (db/get-db repo)
:date-formatter (state/get-date-formatter)
:page-name page-name
:db-graph-mode? (config/db-based-graph? repo)})]
(if (config/db-based-graph? repo)
(map (fn [block]
(cond-> (dissoc block :block/properties)
(:block/properties block)
(merge (update-keys (:block/properties block)
(fn [k]
(or ({:heading :logseq.property/heading} k)
(throw (ex-info (str "Don't know how to save graph-parser property " (pr-str k)) {}))))))))
blocks)
blocks))
(catch :default e
(log/error :exception e)
(state/pub-event! [:capture-error {:error e
:payload {:type "Extract-blocks"}}])
(notification/show! "An unexpected error occurred during block extraction." :error)
[]))))
(defn page-name->map
"Wrapper around logseq.graph-parser.block/page-name->map that adds in db"