瀏覽代碼

fix: insert properties will truncate other properties if there's any empty property (#9117)

fix: insert properties not working when there's any empty property
Tienson Qin 2 年之前
父節點
當前提交
b359718f4a

+ 0 - 3
deps/graph-parser/src/logseq/graph_parser/text.cljs

@@ -174,9 +174,6 @@
                  (name k))
       v'
 
-      (string/blank? v')
-      nil
-
       (gp-util/wrapped-by-quotes? v')
       v'
 

+ 2 - 2
src/main/frontend/util/property.cljs

@@ -45,13 +45,13 @@
   [line]
   (boolean
    (and (string? line)
-        (re-find (re-pattern (str "^\\s?[^ ]+" gp-property/colons " ")) line))))
+        (re-find (re-pattern (str "^\\s?[^ ]+" gp-property/colons)) line))))
 
 (defn front-matter-property?
   [line]
   (boolean
    (and (string? line)
-        (util/safe-re-find #"^\s*[^ ]+: " line))))
+        (util/safe-re-find #"^\s*[^ ]+:" line))))
 
 (defn get-property-key
   [line format]

+ 1 - 1
src/test/frontend/handler/repo_conversion_test.cljs

@@ -63,7 +63,7 @@
 
     (is (= {:title 98
             :alias 6
-            :tags 2 :permalink 2
+            :tags 3 :permalink 2
             :name 1 :type 1 :related 1 :sample 1 :click 1 :id 1 :example 1}
            (docs-graph-helper/get-all-page-properties db))
         "Counts for all page properties")

+ 14 - 2
src/test/frontend/util/property_test.cljs

@@ -49,7 +49,7 @@
       "** hello"
 
       (property/remove-properties :markdown "** hello\nx:: y\na::b\n")
-      "** hello\na::b"))
+      "** hello"))
 
   (testing "properties with blank lines"
     (are [x y] (= x y)
@@ -152,7 +152,19 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d")
     "a\nfoo:: [[bar]], [[baz]]\nb"
 
     (property/insert-properties :markdown "" {:foo "\"bar, baz\""})
-    "foo:: \"bar, baz\""))
+    "foo:: \"bar, baz\""
+
+    (property/insert-properties :markdown "abcd\nempty::" {:id "123" :foo "bar"})
+    "abcd\nempty::\nid:: 123\nfoo:: bar"
+
+    (property/insert-properties :markdown "abcd\nempty:: " {:id "123" :foo "bar"})
+    "abcd\nempty:: \nid:: 123\nfoo:: bar"
+
+    (property/insert-properties :markdown "abcd\nempty::" {:id "123"})
+    "abcd\nempty::\nid:: 123"
+
+    (property/insert-properties :markdown "abcd\nempty::\nanother-empty::" {:id "123"})
+    "abcd\nempty::\nanother-empty::\nid:: 123"))
 
 (deftest test-build-properties-str
   (are [x y] (= (property/build-properties-str :mardown x) y)