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 "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 [k' (and k (string/trim (string/lower-case k)))
v' (and v (string/trim v))
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'])))
(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' 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))]
{:properties properties
:page-refs page-refs}))

View File

@ -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!

View File

@ -24,35 +24,38 @@
(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]
(if (and (string? s)
(or (re-find #"[\"|\,||#]+" s)
(re-find page-ref-re 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))))
(distinct))]
(if (or (coll? result)
(and (string? result)
(string/starts-with? result "#")))
(let [result (if coll? result [result])
result (map (fn [s] (string/replace s #"^#+" "")) result)]
(set result))
(first result)))
s))
([s]
(split-page-refs-without-brackets s false))
([s comma?]
(if (and (string? 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 s))))
(distinct))]
(if (or (coll? result)
(and (string? result)
(string/starts-with? result "#")))
(let [result (if coll? result [result])
result (map (fn [s] (string/replace s #"^#+" "")) result)]
(set result))
(first result)))
s)))
(defn extract-level-spaces
[text format]

View File

@ -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]]"]