Skip to content

Commit

Permalink
fix: insert properties will truncate other properties if there's any …
Browse files Browse the repository at this point in the history
…empty property (logseq#9117)

fix: insert properties not working when there's any empty property
  • Loading branch information
tiensonqin authored Apr 18, 2023
1 parent 9adb864 commit b359718
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 0 additions & 3 deletions deps/graph-parser/src/logseq/graph_parser/text.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@
(name k))
v'

(string/blank? v')
nil

(gp-util/wrapped-by-quotes? v')
v'

Expand Down
4 changes: 2 additions & 2 deletions src/main/frontend/util/property.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/test/frontend/handler/repo_conversion_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 14 additions & 2 deletions src/test/frontend/util/property_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b359718

Please sign in to comment.