fix: head's background color is not rendered

Related to #1267
pull/1274/head
Tienson Qin 2021-02-04 23:51:15 +08:00
parent 46a5ce1963
commit f526399d63
4 changed files with 56 additions and 38 deletions

View File

@ -141,6 +141,9 @@
(update "created_at" util/safe-parse-int) (update "created_at" util/safe-parse-int)
(update "last_modified_at" util/safe-parse-int))) (update "last_modified_at" util/safe-parse-int)))
(defonce non-parsing-properties
(atom #{"background_color"}))
(defn extract-properties (defn extract-properties
[[_ properties] _start-pos _end-pos] [[_ properties] _start-pos _end-pos]
(let [properties (into {} properties) (let [properties (into {} properties)
@ -155,14 +158,25 @@
(distinct)) (distinct))
properties (->> properties properties (->> properties
(medley/map-kv (fn [k v] (medley/map-kv (fn [k v]
(let [k' (and k (string/trim (string/lower-case k))) (let [v (string/trim v)]
v' (and v (string/trim v)) (cond
v' (if (and k' v' (and (= "\"" (first v) (last v))) ; wrapped in ""
(contains? config/markers k') [(string/lower-case k) (string/trim (subs v 1 (dec (count v))))]
(util/safe-parse-int v'))
(util/safe-parse-int v') (contains? @non-parsing-properties (string/lower-case k))
(text/split-page-refs-without-brackets v'))] [(string/lower-case k) v]
[k' v'])))
:else
(let [k' (and k (string/trim (string/lower-case k)))
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' comma?))]
[k' v'])))))
(->schema-properties))] (->schema-properties))]
{:properties properties {:properties properties
:page-refs page-refs})) :page-refs page-refs}))

View File

@ -427,9 +427,10 @@
(save-block-if-changed! block value nil)) (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} ([{:block/keys [uuid content meta file page dummy? format repo pre-block? content ref-pages ref-blocks] :as block}
value 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 :or {rebuild-content? true
custom-properties nil custom-properties nil
init-properties nil
remove-properties nil} remove-properties nil}
:as opts}] :as opts}]
(let [repo (or repo (state/get-current-repo)) (let [repo (or repo (state/get-current-repo))
@ -464,8 +465,9 @@
text-properties (text/extract-properties value) text-properties (text/extract-properties value)
old-hidden-properties (select-keys (:block/properties block) text/hidden-properties) old-hidden-properties (select-keys (:block/properties block) text/hidden-properties)
properties (merge old-hidden-properties properties (merge old-hidden-properties
custom-properties init-properties
text-properties) text-properties
custom-properties)
remove-properties (-> remove-properties (->
(set/difference (set (keys (:block/properties block))) (set/difference (set (keys (:block/properties block)))
(set (keys text-properties)) (set (keys text-properties))
@ -1138,7 +1140,7 @@
(when-not (:block/pre-block? block) (when-not (:block/pre-block? block)
(let [{:block/keys [content properties]} block] (let [{:block/keys [content properties]} block]
(cond (cond
(and (get properties key) (and (string? (get properties key))
(= (string/trim (get properties key)) value)) (= (string/trim (get properties key)) value))
nil nil
@ -1415,7 +1417,7 @@
;; maybe we shouldn't save the block/file in "will-unmount" event? ;; maybe we shouldn't save the block/file in "will-unmount" event?
(save-block-if-changed! block new-value (save-block-if-changed! block new-value
(merge (merge
{:custom-properties properties} {:init-properties properties}
opts)))) opts))))
(defn save-block! (defn save-block!

View File

@ -24,35 +24,38 @@
(subs s 2 (- (count s) 2)) (subs s 2 (- (count s) 2))
s))) s)))
;; E.g "Foo Bar \"Bar Baz\"" ;; E.g "Foo Bar"
(defn sep-by-comma-or-quote (defn sep-by-comma
[s] [s]
(when s (when s
(some->> (some->>
(string/split s #"[\"|\,|]{1}") (string/split s #"[\,|]{1}")
(remove string/blank?) (remove string/blank?)
(map string/trim)))) (map string/trim))))
(defn split-page-refs-without-brackets (defn split-page-refs-without-brackets
[s] ([s]
(if (and (string? s) (split-page-refs-without-brackets s false))
(or (re-find #"[\"|\,||#]+" s) ([s comma?]
(re-find page-ref-re s))) (if (and (string? s)
(let [result (->> (string/split s page-ref-re-2) ;; Either a page ref, a tag or a comma separated collection
(remove string/blank?) (or (re-find page-ref-re s)
(mapcat (fn [s] (re-find (if comma? #"[\,||#]+" #"#") s)))
(if (page-ref? s) (let [result (->> (string/split s page-ref-re-2)
[(page-ref-un-brackets! s)] (remove string/blank?)
(sep-by-comma-or-quote s)))) (mapcat (fn [s]
(distinct))] (if (page-ref? s)
(if (or (coll? result) [(page-ref-un-brackets! s)]
(and (string? result) (sep-by-comma s))))
(string/starts-with? result "#"))) (distinct))]
(let [result (if coll? result [result]) (if (or (coll? result)
result (map (fn [s] (string/replace s #"^#+" "")) result)] (and (string? result)
(set result)) (string/starts-with? result "#")))
(first result))) (let [result (if coll? result [result])
s)) result (map (fn [s] (string/replace s #"^#+" "")) result)]
(set result))
(first result)))
s)))
(defn extract-level-spaces (defn extract-level-spaces
[text format] [text format]

View File

@ -19,13 +19,12 @@
"[single bracket]" "[single bracket]" "[single bracket]" "[single bracket]"
"no brackets" "no brackets")) "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"]
"[[foo]] [[bar]]" ["[[foo]] [[bar]]"] "[[foo]] [[bar]]" ["[[foo]] [[bar]]"]
"[[foo]],[[bar]]" ["[[foo]]", "[[bar]]"] "[[foo]],[[bar]]" ["[[foo]]", "[[bar]]"]
"[[foo]], [[bar]]" ["[[foo]]", "[[bar]]"] "[[foo]], [[bar]]" ["[[foo]]", "[[bar]]"]