Browse Source

enhance: copy replace block-ref and embeds

rcmerci 4 years ago
parent
commit
4f8723790a
1 changed files with 5 additions and 22 deletions
  1. 5 22
      src/main/frontend/handler/editor.cljs

+ 5 - 22
src/main/frontend/handler/editor.cljs

@@ -26,6 +26,7 @@
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.ui :as ui-handler]
             [frontend.handler.ui :as ui-handler]
+            [frontend.handler.export :as export]
             [frontend.image :as image]
             [frontend.image :as image]
             [frontend.modules.outliner.core :as outliner-core]
             [frontend.modules.outliner.core :as outliner-core]
             [frontend.modules.outliner.tree :as tree]
             [frontend.modules.outliner.tree :as tree]
@@ -1045,28 +1046,10 @@
         level-blocks-uuid-map (into {} (mapv (fn [b] [(:block/uuid b) b]) (vals level-blocks-map)))
         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*)
         level-blocks (mapv (fn [uuid] (get level-blocks-uuid-map uuid)) block-ids*)
         tree (blocks-vec->tree level-blocks)
         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
 (defn copy-selection-blocks
   []
   []