Browse Source

fix: remove id property when copy block(s) text (#198)

* fix: remove id property when copy block(s) text
Tienson Qin 5 years ago
parent
commit
5c53b5494b

+ 4 - 0
src/main/frontend/components/onboarding.cljs

@@ -206,6 +206,10 @@
        [:a {:href "https://logseq.github.io/page/changelog"
             :target "_blank"}
         (t :help/changelog)]]
+      [:li
+       [:a {:href "https://logseq.github.io/page/faq"
+            :target "_blank"}
+        "FAQ"]]
       [:li
        [:a {:href "https://logseq.github.io/"
             :target "_blank"}

+ 6 - 1
src/main/frontend/handler/common.cljs

@@ -3,7 +3,8 @@
             [frontend.state :as state]
             [cljs-bean.core :as bean]
             [promesa.core :as p]
-            [frontend.util :as util]))
+            [frontend.util :as util]
+            [frontend.text :as text]))
 
 (defn check-changed-files-status
   []
@@ -17,3 +18,7 @@
            (state/set-changed-files! repo files)))
        (p/catch (fn [error]
                   (js/console.dir error)))))))
+
+(defn copy-to-clipboard-without-id-property!
+  [content]
+  (util/copy-to-clipboard! (text/remove-id-property content)))

+ 3 - 2
src/main/frontend/handler/editor.cljs

@@ -1,5 +1,6 @@
 (ns frontend.handler.editor
   (:require [frontend.state :as state]
+            [frontend.handler.common :as common-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.git :as git-handler]
             [frontend.handler.ui :as ui-handler]
@@ -1146,7 +1147,7 @@
           content (if (false? up?) (reverse content) content)
           content (string/join "" content)]
       (when-not (string/blank? content)
-        (util/copy-to-clipboard! content)))))
+        (common-handler/copy-to-clipboard-without-id-property! content)))))
 
 (defn cut-selection-blocks
   []
@@ -1242,7 +1243,7 @@
   [block-id]
   (when-let [block (db/pull [:block/uuid block-id])]
     (let [content (:block/content block)]
-      (util/copy-to-clipboard! content)
+      (common-handler/copy-to-clipboard-without-id-property! content)
       (delete-block-aux! block false))))
 
 (defonce select-start-block-state (atom nil))

+ 4 - 2
src/main/frontend/handler/export.cljs

@@ -5,13 +5,15 @@
             [cljs-bean.core :as bean]
             [clojure.string :as string]
             [goog.dom :as gdom]
-            [frontend.publishing.html :as html]))
+            [frontend.publishing.html :as html]
+            [frontend.text :as text]
+            [frontend.handler.common :as common-handler]))
 
 (defn copy-block!
   [block-id]
   (when-let [block (db/pull [:block/uuid block-id])]
     (let [content (:block/content block)]
-      (util/copy-to-clipboard! content))))
+      (common-handler/copy-to-clipboard-without-id-property! content))))
 
 (defn copy-block-as-json!
   [block-id]

+ 13 - 0
src/main/frontend/text.cljs

@@ -61,6 +61,19 @@
     (->> (concat title-lines body)
          (string/join "\n"))))
 
+(defn remove-id-property
+  [content]
+  (let [lines (->> (string/split-lines content)
+                   (remove #(let [s (string/lower-case (string/trim %))]
+                              (and
+                               (or (string/starts-with? s ":id:")
+                                   (string/starts-with? s ":custom_id:"))
+                               (let [id (and
+                                         (> (count s) 36)
+                                         (subs s (- (count s) 36)))]
+                                 (and id (util/uuid-string? id)))))))]
+    (string/join "\n" lines)))
+
 (defn build-properties-str
   [properties]
   (when (seq properties)