Browse Source

Fix format property reference when org mode

glippi 2 years ago
parent
commit
7249651345

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

@@ -7,7 +7,11 @@
             [goog.string.format]))
 
 (def colons "Property delimiter for markdown mode" "::")
-
+(defn colons-org 
+  "Property delimiter for org mode"
+  [property]
+  (str ":" property ":"))
+ 
 (defn ->block-content
   "Creates a block content string from properties map"
   [properties]

+ 11 - 10
src/main/frontend/handler/page.cljs

@@ -275,24 +275,25 @@
                       (str lhs new-tag)))))
 
 (defn- replace-property-ref!
-  [content old-name new-name]
+  [content old-name new-name format]
   (let [new-name (keyword (string/replace (string/lower-case new-name) #"\s+" "-"))
-        old-property (str old-name gp-property/colons)
-        new-property (str (name new-name) gp-property/colons)]
+        org-format? (= :org format)
+        old-property (if org-format? (gp-property/colons-org old-name) (str old-name gp-property/colons))
+        new-property (if org-format? (gp-property/colons-org (name new-name)) (str (name new-name) gp-property/colons))]
     (util/replace-ignore-case content old-property new-property)))
 
 (defn- replace-old-page!
   "Unsanitized names"
-  [content old-name new-name]
+  [content old-name new-name format]
   (when (and (string? content) (string? old-name) (string? new-name))
     (-> content
         (replace-page-ref! old-name new-name)
         (replace-tag-ref! old-name new-name)
-        (replace-property-ref! old-name new-name))))
+        (replace-property-ref! old-name new-name format))))
 
 (defn- walk-replace-old-page!
   "Unsanitized names"
-  [form old-name new-name]
+  [form old-name new-name format]
   (walk/postwalk (fn [f]
                    (cond
                      (and (vector? f)
@@ -305,7 +306,7 @@
                      (string? f)
                      (if (= f old-name)
                        new-name
-                       (replace-old-page! f old-name new-name))
+                       (replace-old-page! f old-name new-name format))
 
                      (and (keyword f) (= (name f) old-name))
                      (keyword (string/replace (string/lower-case new-name) #"\s+" "-"))
@@ -404,11 +405,11 @@
         page-ids (->> (map (fn [b]
                              {:db/id (:db/id (:block/page b))}) blocks)
                       (set))
-        tx       (->> (map (fn [{:block/keys [uuid content properties] :as block}]
-                             (let [content    (let [content' (replace-old-page! content old-original-name new-name)]
+        tx       (->> (map (fn [{:block/keys [uuid content properties format] :as block}]
+                             (let [content    (let [content' (replace-old-page! content old-original-name new-name format)]
                                                 (when-not (= content' content)
                                                   content'))
-                                   properties (let [properties' (walk-replace-old-page! properties old-original-name new-name)]
+                                   properties (let [properties' (walk-replace-old-page! properties old-original-name new-name format)]
                                                 (when-not (= properties' properties)
                                                   properties'))]
                                (when (or content properties)