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
pull/9138/head
Tienson Qin 2023-04-18 14:01:13 +08:00 committed by GitHub
parent 9adb8646b0
commit b359718f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 8 deletions

View File

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

View File

@ -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]

View File

@ -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")

View File

@ -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)