浏览代码

fix: store #tag as #[[uuid]] internally

Tienson Qin 10 月之前
父节点
当前提交
cc27407699

+ 11 - 8
deps/db/src/logseq/db/frontend/content.cljs

@@ -30,9 +30,13 @@
       (reduce
        (fn [content ref]
          (if (:block/title ref)
-           (string/replace content
-                           (page-ref/->page-ref (:block/uuid ref))
-                           (page-ref/->page-ref (:block/title ref)))
+           (let [content' (if (not (string/includes? (:block/title ref) " "))
+                            (string/replace content
+                                            (str "#" (page-ref/->page-ref (:block/uuid ref)))
+                                            (str "#" (:block/title ref)))
+                            content)]
+             (string/replace content' (page-ref/->page-ref (:block/uuid ref))
+                             (page-ref/->page-ref (:block/title ref))))
            content))
        content
        refs)
@@ -47,9 +51,8 @@
 
 (defn- replace-tag-ref
   [content page-name id]
-  (let [[page wrapped-id] (if (string/includes? page-name " ")
-                            (map page-ref/->page-ref [page-name id])
-                            [page-name id])
+  (let [page (if (string/includes? page-name " ") (page-ref/->page-ref page-name) page-name)
+        wrapped-id (page-ref/->page-ref id)
         page-name (common-util/format "#%s" page)
         r (common-util/format "#%s" wrapped-id)]
     ;; hash tag parsing rules https://github.com/logseq/mldoc/blob/701243eaf9b4157348f235670718f6ad19ebe7f8/test/test_markdown.ml#L631
@@ -105,7 +108,7 @@
       item)
     item))
 
-(defn replace-tags-with-page-refs
+(defn replace-tags-with-id-refs
   "Replace tags in content with page-ref ids. Ignore case because tags in
   content can have any case and still have a valid ref"
   [content tags]
@@ -116,7 +119,7 @@
         (-> content
             ;; #[[favorite book]]
             (common-util/replace-ignore-case
-             (str "#" page-ref/left-brackets (:block/title tag) page-ref/right-brackets)
+             (str "#" (page-ref/->page-ref (:block/title tag)))
              id-ref)
             ;; #book
             (common-util/replace-ignore-case (str "#" (:block/title tag)) id-ref))))

+ 1 - 1
deps/db/test/logseq/db/frontend/content_test.cljs

@@ -5,7 +5,7 @@
 (deftest replace-tags-with-page-refs
   (testing "tags with overlapping names get replaced correctly"
     (is (= "string [[foo]] string2 [[foo-bar]]"
-           (db-content/replace-tags-with-page-refs
+           (db-content/replace-tags-with-id-refs
             "string #foo string2 #foo-bar"
             [{:block/title "foo" :block/uuid "foo"}
              {:block/title "foo-bar" :block/uuid "foo-bar"}])))))

+ 1 - 1
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -228,7 +228,7 @@
                            (map :block/title)))
               true
               (update :block/title
-                      db-content/replace-tags-with-page-refs
+                      db-content/replace-tags-with-id-refs
                       (->> original-tags
                            (remove convert-tag?')
                            (map #(add-uuid-to-page-map % (:page-names-to-uuids per-file-state)))))

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

@@ -64,7 +64,8 @@
             [logseq.outliner.core :as outliner-core]
             [promesa.core :as p]
             [rum.core :as rum]
-            [logseq.outliner.property :as outliner-property]))
+            [logseq.outliner.property :as outliner-property]
+            [datascript.core :as d]))
 
 ;; FIXME: should support multiple images concurrently uploading
 
@@ -3444,12 +3445,13 @@
 (defn- db-collapsable?
   [block]
   (let [class-properties (:classes-properties (outliner-property/get-block-classes-properties (db/get-db) (:db/id block)))
-        properties (->> (keys (:block/properties block))
+        properties (->> (map :a (d/datoms (db/get-db) :eavt (:db/id block)))
                         (map db/entity)
                         (concat class-properties)
                         (remove (fn [e] (db-property/db-attribute-properties (:db/ident e))))
                         (remove outliner-property/property-with-other-position?)
-                        (remove (fn [e] (:hide? (:block/schema e)))))]
+                        (remove (fn [e] (:hide? (:block/schema e))))
+                        (remove nil?))]
     (or (seq properties)
         (ldb/class-instance? (db/entity :logseq.class/Query) block))))
 

+ 1 - 1
src/main/frontend/handler/paste.cljs

@@ -37,7 +37,7 @@
                              (-> block
                                  (dissoc :block/tags)
                                  (update :block/title (fn [title]
-                                                        (let [title' (db-content/replace-tags-with-page-refs title refs)]
+                                                        (let [title' (db-content/replace-tags-with-id-refs title refs)]
                                                           (db-content/title-ref->id-ref title' refs)))))))))]
       (editor-handler/paste-blocks blocks' {:keep-uuid? true}))))