mirror of https://github.com/logseq/logseq
parent
46a5ce1963
commit
f526399d63
|
@ -141,6 +141,9 @@
|
|||
(update "created_at" util/safe-parse-int)
|
||||
(update "last_modified_at" util/safe-parse-int)))
|
||||
|
||||
(defonce non-parsing-properties
|
||||
(atom #{"background_color"}))
|
||||
|
||||
(defn extract-properties
|
||||
[[_ properties] _start-pos _end-pos]
|
||||
(let [properties (into {} properties)
|
||||
|
@ -155,14 +158,25 @@
|
|||
(distinct))
|
||||
properties (->> properties
|
||||
(medley/map-kv (fn [k v]
|
||||
(let [v (string/trim v)]
|
||||
(cond
|
||||
(and (= "\"" (first v) (last v))) ; wrapped in ""
|
||||
[(string/lower-case k) (string/trim (subs v 1 (dec (count v))))]
|
||||
|
||||
(contains? @non-parsing-properties (string/lower-case k))
|
||||
[(string/lower-case k) v]
|
||||
|
||||
:else
|
||||
(let [k' (and k (string/trim (string/lower-case k)))
|
||||
v' (and v (string/trim v))
|
||||
v' v
|
||||
;; built-in collections
|
||||
comma? (contains? #{"tags" "alias"} k)
|
||||
v' (if (and k' v'
|
||||
(contains? config/markers k')
|
||||
(util/safe-parse-int v'))
|
||||
(util/safe-parse-int v')
|
||||
(text/split-page-refs-without-brackets v'))]
|
||||
[k' v'])))
|
||||
(text/split-page-refs-without-brackets v' comma?))]
|
||||
[k' v'])))))
|
||||
(->schema-properties))]
|
||||
{:properties properties
|
||||
:page-refs page-refs}))
|
||||
|
|
|
@ -427,9 +427,10 @@
|
|||
(save-block-if-changed! block value nil))
|
||||
([{:block/keys [uuid content meta file page dummy? format repo pre-block? content ref-pages ref-blocks] :as block}
|
||||
value
|
||||
{:keys [indent-left? custom-properties remove-properties rebuild-content? chan chan-callback]
|
||||
{:keys [indent-left? init-properties custom-properties remove-properties rebuild-content? chan chan-callback]
|
||||
:or {rebuild-content? true
|
||||
custom-properties nil
|
||||
init-properties nil
|
||||
remove-properties nil}
|
||||
:as opts}]
|
||||
(let [repo (or repo (state/get-current-repo))
|
||||
|
@ -464,8 +465,9 @@
|
|||
text-properties (text/extract-properties value)
|
||||
old-hidden-properties (select-keys (:block/properties block) text/hidden-properties)
|
||||
properties (merge old-hidden-properties
|
||||
custom-properties
|
||||
text-properties)
|
||||
init-properties
|
||||
text-properties
|
||||
custom-properties)
|
||||
remove-properties (->
|
||||
(set/difference (set (keys (:block/properties block)))
|
||||
(set (keys text-properties))
|
||||
|
@ -1138,7 +1140,7 @@
|
|||
(when-not (:block/pre-block? block)
|
||||
(let [{:block/keys [content properties]} block]
|
||||
(cond
|
||||
(and (get properties key)
|
||||
(and (string? (get properties key))
|
||||
(= (string/trim (get properties key)) value))
|
||||
nil
|
||||
|
||||
|
@ -1415,7 +1417,7 @@
|
|||
;; maybe we shouldn't save the block/file in "will-unmount" event?
|
||||
(save-block-if-changed! block new-value
|
||||
(merge
|
||||
{:custom-properties properties}
|
||||
{:init-properties properties}
|
||||
opts))))
|
||||
|
||||
(defn save-block!
|
||||
|
|
|
@ -24,26 +24,29 @@
|
|||
(subs s 2 (- (count s) 2))
|
||||
s)))
|
||||
|
||||
;; E.g "Foo Bar \"Bar Baz\""
|
||||
(defn sep-by-comma-or-quote
|
||||
;; E.g "Foo Bar"
|
||||
(defn sep-by-comma
|
||||
[s]
|
||||
(when s
|
||||
(some->>
|
||||
(string/split s #"[\"|\,|,]{1}")
|
||||
(string/split s #"[\,|,]{1}")
|
||||
(remove string/blank?)
|
||||
(map string/trim))))
|
||||
|
||||
(defn split-page-refs-without-brackets
|
||||
[s]
|
||||
([s]
|
||||
(split-page-refs-without-brackets s false))
|
||||
([s comma?]
|
||||
(if (and (string? s)
|
||||
(or (re-find #"[\"|\,|,|#]+" s)
|
||||
(re-find page-ref-re s)))
|
||||
;; Either a page ref, a tag or a comma separated collection
|
||||
(or (re-find page-ref-re s)
|
||||
(re-find (if comma? #"[\,|,|#]+" #"#") s)))
|
||||
(let [result (->> (string/split s page-ref-re-2)
|
||||
(remove string/blank?)
|
||||
(mapcat (fn [s]
|
||||
(if (page-ref? s)
|
||||
[(page-ref-un-brackets! s)]
|
||||
(sep-by-comma-or-quote s))))
|
||||
(sep-by-comma s))))
|
||||
(distinct))]
|
||||
(if (or (coll? result)
|
||||
(and (string? result)
|
||||
|
@ -52,7 +55,7 @@
|
|||
result (map (fn [s] (string/replace s #"^#+" "")) result)]
|
||||
(set result))
|
||||
(first result)))
|
||||
s))
|
||||
s)))
|
||||
|
||||
(defn extract-level-spaces
|
||||
[text format]
|
||||
|
|
|
@ -19,13 +19,12 @@
|
|||
"[single bracket]" "[single bracket]"
|
||||
"no brackets" "no brackets"))
|
||||
|
||||
(deftest sep-by-comma-or-quote
|
||||
(deftest sep-by-comma
|
||||
[]
|
||||
(are [x y] (= (text/sep-by-comma-or-quote x) y)
|
||||
(are [x y] (= (text/sep-by-comma x) y)
|
||||
"foo,bar" ["foo" "bar"]
|
||||
"foo, bar" ["foo" "bar"]
|
||||
"foo bar" ["foo bar"]
|
||||
"foo \"bar\"" ["foo" "bar"]
|
||||
"[[foo]] [[bar]]" ["[[foo]] [[bar]]"]
|
||||
"[[foo]],[[bar]]" ["[[foo]]", "[[bar]]"]
|
||||
"[[foo]], [[bar]]" ["[[foo]]", "[[bar]]"]
|
||||
|
|
Loading…
Reference in New Issue