Skip to content

Commit

Permalink
fix: properties not work well for org mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed May 24, 2021
1 parent b71ae70 commit 87ded73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/main/frontend/handler/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
:else
(subs content 0 pos))
content (property/remove-built-in-properties (:block/format block)
content)]
content)]
(clear-selection! nil)
(state/set-editing! edit-input-id content block text-range move-cursor?))))))

Expand Down Expand Up @@ -640,7 +640,7 @@
:data [new-block]})))))

(defn update-timestamps-content!
[{:block/keys [repeated? marker] :as block} content]
[{:block/keys [repeated? marker format] :as block} content]
(if repeated?
(let [scheduled-ast (block-handler/get-scheduled-ast block)
deadline-ast (block-handler/get-deadline-ast block)
Expand All @@ -654,7 +654,7 @@
(when content
(str (string/trimr content)
"\n"
(util/format "* %s -> DONE [%s]"
(util/format (str (if (= format :org) "-" "*") " %s -> DONE [%s]")
marker
(date/get-local-date-time-string)))))
content))
Expand Down
9 changes: 6 additions & 3 deletions src/main/frontend/handler/extract.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,12 @@
(println "Parsing : " path)
(when content
;; TODO: remove `text/scheduled-deadline-dash->star` once migration is done
(let [content (text/scheduled-deadline-dash->star content)
utf8-content (utf8/encode content)]
(extract-blocks-pages repo-url path content utf8-content)))))
(let [org? (= "org" (string/lower-case (util/get-file-ext path)))]
(let [content (if org?
content
(text/scheduled-deadline-dash->star content))
utf8-content (utf8/encode content)]
(extract-blocks-pages repo-url path content utf8-content))))))
(remove empty?))]
(when (seq result)
(let [[pages block-ids blocks] (apply map concat result)
Expand Down
11 changes: 8 additions & 3 deletions src/main/frontend/util/property.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
(or (simplified-property? s)
(and org? (org-property? s)))) properties-and-body)
body (if org?
(remove (fn [s] (= (string/trim s) properties-start)) body)
(remove (fn [s] (contains? #{properties-start properties-end} (string/trim s))) body)
body)
properties-in-content (->> (map #(get-property-key % format) properties-lines)
(remove nil?)
Expand All @@ -129,6 +129,8 @@
(when org? [properties-start])
built-in-properties-area
properties-lines
(when org?
[properties-end])
body)]
(string/join "\n" body))
content)))
Expand Down Expand Up @@ -244,8 +246,11 @@

(defn remove-built-in-properties
[format content]
(reduce (fn [content key]
(remove-property format key content)) content built-in-properties))
(let [content (reduce (fn [content key]
(remove-property format key content)) content built-in-properties)]
(if (= format :org)
(string/replace-first content ":PROPERTIES:\n:END:" "")
content)))

(defn ->new-properties
"New syntax: key:: value"
Expand Down

0 comments on commit 87ded73

Please sign in to comment.