diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index 8f75c336fc..6adcf709b8 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -1392,7 +1392,7 @@ (editor-handler/unhighlight-blocks!) (let [block (or (db/pull [:block/uuid (:block/uuid block)]) block) f #(let [cursor-range (util/caret-range (gdom/getElement block-id)) - content (property/remove-built-in-properties! (:block/format block) + content (property/remove-built-in-properties (:block/format block) content)] (state/set-editing! edit-input-id diff --git a/src/main/frontend/format/block.cljs b/src/main/frontend/format/block.cljs index 132937ce83..81ca2400d2 100644 --- a/src/main/frontend/format/block.cljs +++ b/src/main/frontend/format/block.cljs @@ -412,7 +412,7 @@ (drop-while #(= ["Break_Line"] %)))] (recur headings (conj block-body ["Paragraph" other-body]) (rest blocks) timestamps' properties last-pos last-level children)) - (property/properties-block? block) + (property/properties-ast? block) (let [properties (extract-properties block start_pos end_pos)] (recur headings block-body (rest blocks) timestamps properties last-pos last-level children)) diff --git a/src/main/frontend/handler/common.cljs b/src/main/frontend/handler/common.cljs index 5b41a4413c..01b9332249 100644 --- a/src/main/frontend/handler/common.cljs +++ b/src/main/frontend/handler/common.cljs @@ -57,7 +57,7 @@ (defn copy-to-clipboard-without-id-property! [format content] - (util/copy-to-clipboard! (property/remove-id-property! format content))) + (util/copy-to-clipboard! (property/remove-id-property format content))) (defn config-with-document-mode [config] diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index c8fd85fb9c..f3ac1a89aa 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -226,7 +226,7 @@ :else (subs content 0 pos)) - content (property/remove-built-in-properties! (:block/format block) + content (property/remove-built-in-properties (:block/format block) content)] (clear-selection! nil) (state/set-editing! edit-input-id content block text-range move-cursor?)))))) @@ -572,7 +572,7 @@ (:block/properties block)) value (or (when new-marker? - (property/insert-property! (:block/format block) + (property/insert-property (:block/format block) value new-marker ts)) @@ -638,7 +638,7 @@ [content format marker] (if (state/enable-timetracking?) (let [marker (string/lower-case marker)] - (property/insert-property! format content marker (util/time-ms))) + (property/insert-property format content marker (util/time-ms))) content)) (defn check @@ -818,8 +818,8 @@ (assoc properties key value) (dissoc properties key)) content (if value - (property/insert-property! format content key value) - (property/remove-property! format key content)) + (property/insert-property format content key value) + (property/remove-property format key content)) block (outliner-core/block {:block/uuid block-id :block/properties properties :block/content content})] @@ -1232,7 +1232,7 @@ (defn- clean-content! [format content] (->> (text/remove-level-spaces content format) - (property/remove-properties! format) + (property/remove-properties format) string/trim)) (defn insert-command! @@ -1899,8 +1899,8 @@ [(:block/content %) (:block/title %)]) new-content (->> new-content - (property/remove-property! format "id") - (property/remove-property! format "custom_id"))] + (property/remove-property format "id") + (property/remove-property format "custom_id"))] (conj {:block/uuid uuid :block/page (select-keys page [:db/id]) :block/file (select-keys file [:db/id]) @@ -1946,8 +1946,8 @@ (paste-block-tree-at-point tree [:template :including-parent] (fn [content] (->> content - (property/remove-property! format "template") - (property/remove-property! format "including-parent") + (property/remove-property format "template") + (property/remove-property format "including-parent") template/resolve-dynamic-template!))) (clear-when-saved!) (insert-command! id "" format {}) diff --git a/src/main/frontend/handler/extract.cljs b/src/main/frontend/handler/extract.cljs index 295d1f81c9..6a8e0e50b7 100644 --- a/src/main/frontend/handler/extract.cljs +++ b/src/main/frontend/handler/extract.cljs @@ -181,7 +181,7 @@ ast (mldoc/->edn content (mldoc/default-config format)) first-block (ffirst ast) - properties (let [properties (and (property/properties-block? first-block) + properties (let [properties (and (property/properties-ast? first-block) (->> (last first-block) (into {}) (walk/keywordize-keys)))] diff --git a/src/main/frontend/handler/page.cljs b/src/main/frontend/handler/page.cljs index e83a16a63f..2a5a9616e2 100644 --- a/src/main/frontend/handler/page.cljs +++ b/src/main/frontend/handler/page.cljs @@ -108,7 +108,7 @@ new-properties (assoc properties key value) content (:block/content pre-block) front-matter? (property/front-matter? content) - new-content (property/insert-property! format content key value front-matter?) + new-content (property/insert-property format content key value front-matter?) block {:db/id (:db/id pre-block) :block/properties new-properties :block/content new-content diff --git a/src/main/frontend/search/db.cljs b/src/main/frontend/search/db.cljs index 02c95942e3..27e7874340 100644 --- a/src/main/frontend/search/db.cljs +++ b/src/main/frontend/search/db.cljs @@ -17,7 +17,7 @@ (defn block->index [{:block/keys [uuid content format page] :as block}] (when-let [result (->> (text/remove-level-spaces content format) - (property/remove-id-property! format))] + (property/remove-id-property format))] {:id (:db/id block) :uuid (str uuid) :page page diff --git a/src/main/frontend/util/property.cljs b/src/main/frontend/util/property.cljs index f95b090e00..84e674408e 100644 --- a/src/main/frontend/util/property.cljs +++ b/src/main/frontend/util/property.cljs @@ -55,7 +55,7 @@ (when-let [key (get-property-key line :org)] (not (contains? #{:PROPERTIES :END} key)))))) -(defn remove-properties! +(defn remove-properties [format content] (let [org? (= format :org)] (cond @@ -137,9 +137,9 @@ [s] (string/starts-with? s "---\n")) -(defn insert-property! +(defn insert-property ([format content key value] - (insert-property! format content key value false)) + (insert-property format content key value false)) ([format content key value front-matter?] (when (and (not (string/blank? (name key))) (not (string/blank? (str value)))) @@ -207,9 +207,9 @@ :else content))))) -(defn remove-property! +(defn remove-property ([format key content] - (remove-property! format key content true)) + (remove-property format key content true)) ([format key content first?] (when (not (string/blank? (name key))) (let [format (or format :markdown) @@ -224,14 +224,14 @@ (string/starts-with? s (str key ":: ")))))))] (string/join "\n" lines))))))) -(defn remove-id-property! +(defn remove-id-property [format content] - (remove-property! format "id" content false)) + (remove-property format "id" content false)) -(defn remove-built-in-properties! +(defn remove-built-in-properties [format content] (reduce (fn [content key] - (remove-property! format key content)) content built-in-properties)) + (remove-property format key content)) content built-in-properties)) (defn ->new-properties "New syntax: key:: value" @@ -254,7 +254,7 @@ content)) content)) -(defn add-page-properties! +(defn add-page-properties [page-format properties-content properties] (let [properties (medley/map-keys name properties) lines (string/split-lines properties-content) @@ -294,7 +294,7 @@ (config/properties-wrapper-pattern page-format) (string/join "\n" lines)))) -(defn properties-block? +(defn properties-ast? [block] (and (vector? block) diff --git a/src/test/frontend/util/property_test.cljs b/src/test/frontend/util/property_test.cljs index ff32cc68f0..574321fd81 100644 --- a/src/test/frontend/util/property_test.cljs +++ b/src/test/frontend/util/property_test.cljs @@ -3,42 +3,69 @@ [frontend.util.property :as property])) (deftest remove-id-property - (are [x y] (= (property/remove-id-property! :org x) y) - "hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\n:END:\n" - "hello\n:PROPERTIES:\n:END:" + (testing "org" + (are [x y] (= (property/remove-id-property :org x) y) + "hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\n:END:\n" + "hello\n:PROPERTIES:\n:END:" - "hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\na: b\n:END:\n" - "hello\n:PROPERTIES:\na: b\n:END:")) + "hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\na: b\n:END:\n" + "hello\n:PROPERTIES:\na: b\n:END:")) + (testing "markdown" + (are [x y] (= (property/remove-id-property :markdown x) y) + "hello\nid:: f9873a81-07b9-4246-b910-53a6f5ec7e04" + "hello" -(deftest test-remove-properties! + "hello\nid:: f9873a81-07b9-4246-b910-53a6f5ec7e04\n\nworld" + "hello\n\nworld" + + "hello\naa:: bb\nid:: f9873a81-07b9-4246-b910-53a6f5ec7e04\n\nworld" + "hello\naa:: bb\n\nworld" + ) + ) + ) + +(deftest test-remove-properties (testing "properties with non-blank lines" (are [x y] (= x y) - (property/remove-properties! :org "** hello\n:PROPERTIES:\n:x: y\n:END:\n") + (property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n:END:\n") "** hello" - (property/remove-properties! :org "** hello\n:PROPERTIES:\n:x: y\na:b\n:END:\n") - "** hello")) + (property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\na:b\n:END:\n") + "** hello" + + (property/remove-properties :markdown "** hello\nx:: y\na:: b\n") + "** hello" + + (property/remove-properties :markdown "** hello\nx:: y\na::b\n") + "** hello\na::b")) + (testing "properties with blank lines" (are [x y] (= x y) - (property/remove-properties! :org "** hello\n:PROPERTIES:\n\n:x: y\n:END:\n") + (property/remove-properties :org "** hello\n:PROPERTIES:\n\n:x: y\n:END:\n") "** hello" - (property/remove-properties! :org "** hello\n:PROPERTIES:\n:x: y\n\na:b\n:END:\n") - "** hello"))) + (property/remove-properties :org "** hello\n:PROPERTIES:\n:x: y\n\na:b\n:END:\n") + "** hello" + + (property/remove-properties :markdown "** hello\nx:: y\n\na:: b\n") + "** hello\n"))) (deftest test-insert-property (are [x y] (= x y) - (property/insert-property! :org "hello" "a" "b") + (property/insert-property :org "hello" "a" "b") "hello\n:PROPERTIES:\n:a: b\n:END:\n" - (property/insert-property! :org "hello" "a" false) + (property/insert-property :org "hello" "a" false) "hello\n:PROPERTIES:\n:a: false\n:END:\n" - (property/insert-property! :org "hello\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d") + (property/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END:\n" "c" "d") "hello\n:PROPERTIES:\n:a: b\n:c: d\n:END:" - (property/insert-property! :org "hello\n:PROPERTIES:\n:a: b\n:END: world\n" "c" "d") - "hello\n:PROPERTIES:\n:c: d\n:END:\n:PROPERTIES:\n:a: b\n:END: world\n")) + (property/insert-property :org "hello\n:PROPERTIES:\n:a: b\n:END: world\n" "c" "d") + "hello\n:PROPERTIES:\n:c: d\n:END:\n:PROPERTIES:\n:a: b\n:END: world\n" + + (property/insert-property :markdown "hello\na:: b\nworld\n" "c" "d") + "hello\na:: b\nc:: d\nworld")) (deftest test->new-properties (are [x y] (= (property/->new-properties x) y) @@ -63,4 +90,5 @@ "hello\n:PROPERTIES:\n:foo: bar\n:nice\n:END:\nnice" "hello\nfoo:: bar\n:nice\nnice")) -(cljs.test/run-tests) + +#_(cljs.test/run-tests)