Skip to content

Commit

Permalink
enhance: copy replace block-ref and embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
RCmerci authored and tiensonqin committed Jul 22, 2021
1 parent aa9bfd4 commit 4f87237
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
[frontend.handler.repo :as repo-handler]
[frontend.handler.route :as route-handler]
[frontend.handler.ui :as ui-handler]
[frontend.handler.export :as export]
[frontend.image :as image]
[frontend.modules.outliner.core :as outliner-core]
[frontend.modules.outliner.tree :as tree]
Expand Down Expand Up @@ -1045,28 +1046,10 @@
level-blocks-uuid-map (into {} (mapv (fn [b] [(:block/uuid b) b]) (vals level-blocks-map)))
level-blocks (mapv (fn [uuid] (get level-blocks-uuid-map uuid)) block-ids*)
tree (blocks-vec->tree level-blocks)
contents
(mapv (fn [block]
(let [header
(if (= format :markdown)
(str (string/join (repeat (- (:level block) 1) "\t")) "-")
(string/join (repeat (:level block) "*")))]
(str header " " (:block/content block) "\n")))
level-blocks)
content-without-properties
(mapv
(fn [content]
(let [ast (mldoc/->edn content (mldoc/default-config format))
properties-loc
(->> ast
(filterv (fn [[[type _] loc]] (= type "Property_Drawer")))
(mapv second)
first)]
(if properties-loc
(utf8/delete! content (:start_pos properties-loc) (:end_pos properties-loc))
content)))
contents)]
[(string/join content-without-properties) tree]))
top-level-block-uuids (mapv :block/uuid (filterv #(not (vector? %)) tree))
exported-md-contents (mapv #(export/export-blocks-as-markdown repo % "spaces")
top-level-block-uuids)]
[(string/join "\n" (mapv string/trim-newline exported-md-contents)) tree]))

(defn copy-selection-blocks
[]
Expand Down

0 comments on commit 4f87237

Please sign in to comment.