enhance(property): remove empty properties drawer

pull/2777/head
leizhe 2021-09-04 15:11:07 +09:00 committed by Tienson Qin
parent a76df9ce97
commit 229c7f2594
3 changed files with 20 additions and 1 deletions

View File

@ -792,7 +792,7 @@
content (drawer/insert-drawer
format content "logbook"
(util/format (str (if (= :org format) "-" "*")
" State \"DONE\" from \"%s\" [%s]")
" State \"DONE\" from \"%s\" [%s]")
marker
(date/get-date-time-string-3)))]
content)
@ -952,6 +952,7 @@
content (if (nil? value)
(property/remove-property format key content)
(property/insert-property format content key value))
content (property/remove-empty-properties content)
block (outliner-core/block {:block/uuid block-id
:block/properties properties
:block/content content})

View File

@ -75,6 +75,16 @@
(js/console.error e)
content))))
(defn empty-drawer-typ?
[format content typ]
(when-let [drawer-ast (get-drawer-ast format content typ)]
(empty? (last drawer-ast))))
(defn remove-empty-drawer
[format content typ]
(if (empty-drawer-typ? format content typ)
(string/replace content (build-drawer-str typ) "")))
(defn contains-logbook?
[content]
(and (util/safe-re-find (re-pattern (str "(?i)" logbook-start)) content)

View File

@ -38,6 +38,14 @@
(and (string/includes? content properties-start)
(util/safe-re-find properties-end-pattern content)))
(defn remove-empty-properties
[content]
(if (contains-properties? content)
(string/replace content
(re-pattern ":PROPERTIES:\n:END:\n*")
"")
content))
(defn simplified-property?
[line]
(boolean