mirror of https://github.com/logseq/logseq
Remove :block/marker and :block/priority from tx-data
parent
26cace2120
commit
a64f49dc6f
|
@ -0,0 +1,13 @@
|
|||
(ns logseq.common.marker
|
||||
"marker patterns"
|
||||
(:require [clojure.string :as string]))
|
||||
|
||||
(defn marker-pattern [format]
|
||||
(re-pattern
|
||||
(str "^" (if (= format :markdown) "(#+\\s+)?" "(\\*+\\s+)?")
|
||||
"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS)?\\s?")))
|
||||
|
||||
|
||||
(defn clean-marker
|
||||
[content format]
|
||||
(string/replace-first content (marker-pattern format) ""))
|
|
@ -17,7 +17,8 @@
|
|||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[cljs.pprint :as pprint]
|
||||
[logseq.db.frontend.content :as db-content]))
|
||||
[logseq.db.frontend.content :as db-content]
|
||||
[logseq.common.marker :as common-marker]))
|
||||
|
||||
(def ^:private block-map
|
||||
(mu/optional-keys
|
||||
|
@ -257,6 +258,36 @@
|
|||
;; -get-id, -get-parent-id, -get-left-id return block-id
|
||||
;; the :block/parent, :block/left should be datascript lookup ref
|
||||
|
||||
;; TODO: don't parse marker and deprecate typing marker to set status
|
||||
(defn- db-marker-handle
|
||||
[conn m]
|
||||
(or
|
||||
(let [marker (:block/marker m)
|
||||
property (db-property/get-property @conn "status")
|
||||
matched-status-id (when marker
|
||||
(->> (get-in property [:block/schema :values])
|
||||
(some (fn [id]
|
||||
(let [value-e (d/entity @conn [:block/uuid id])
|
||||
value (get-in value-e [:block/schema :value])]
|
||||
(when (= (string/lower-case marker) (string/lower-case value))
|
||||
id))))))]
|
||||
(cond-> m
|
||||
matched-status-id
|
||||
(update :block/properties assoc (:block/uuid property) matched-status-id)
|
||||
|
||||
matched-status-id
|
||||
(update :block/content (fn [content]
|
||||
(common-marker/clean-marker content (get m :block/format :markdown))))
|
||||
matched-status-id
|
||||
(update :db/other-tx (fn [tx]
|
||||
(if-let [task (d/entity @conn [:block/name "task"])]
|
||||
(conj tx [:db/add (:db/id m) :block/tags (:db/id task)])
|
||||
tx)))
|
||||
|
||||
true
|
||||
(dissoc :block/marker :block/priority)))
|
||||
m))
|
||||
|
||||
(extend-type Block
|
||||
otree/INode
|
||||
(-get-id [this conn]
|
||||
|
@ -320,7 +351,7 @@
|
|||
block-uuid (:block/uuid (:data this))
|
||||
eid (or db-id (when block-uuid [:block/uuid block-uuid]))
|
||||
block-entity (d/entity db eid)
|
||||
m (if (and (:block/content m) db-based?)
|
||||
m' (if (and (:block/content m) db-based?)
|
||||
(update m :block/content
|
||||
(fn [content]
|
||||
(db-content/content-without-tags
|
||||
|
@ -332,7 +363,10 @@
|
|||
(str db-content/page-ref-special-chars (:block/uuid tag))))
|
||||
(:block/tags m))
|
||||
(remove nil?)))))
|
||||
m)]
|
||||
m)
|
||||
m (cond->> m'
|
||||
db-based?
|
||||
(db-marker-handle conn))]
|
||||
|
||||
;; Ensure block UUID never changes
|
||||
(when (and db-id block-uuid)
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
(ns frontend.handler.file-based.status
|
||||
"Task (formerly todo) related util fns"
|
||||
(:require [clojure.string :as string]
|
||||
[frontend.util :as util]))
|
||||
[frontend.util :as util]
|
||||
[logseq.common.marker :as common-marker]))
|
||||
|
||||
(defn marker-pattern [format]
|
||||
(re-pattern
|
||||
(str "^" (if (= format :markdown) "(#+\\s+)?" "(\\*+\\s+)?")
|
||||
"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS)?\\s?")))
|
||||
(def marker-pattern common-marker/marker-pattern)
|
||||
|
||||
(def bare-marker-pattern
|
||||
#"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS){1}\s+")
|
||||
|
|
Loading…
Reference in New Issue