enhance: display a warning if a block's content include multiple lists

or headings.
This commit is contained in:
Tienson Qin
2021-11-17 21:07:32 +08:00
parent 1f779774ff
commit ad7de321e0
3 changed files with 17 additions and 7 deletions

View File

@@ -688,11 +688,12 @@
([block]
(parse-block block nil))
([{:block/keys [uuid content page format] :as block} {:keys [with-id?]
:or {with-id? true}}]
:or {with-id? true}}]
(when-not (string/blank? content)
(let [block (dissoc block :block/pre-block?)
ast (format/to-edn content format nil)
new-block (first (extract-blocks ast content with-id? format))
blocks (extract-blocks ast content with-id? format)
new-block (first blocks)
parent-refs (->> (db/get-block-parent (state/get-current-repo) uuid)
:block/path-refs
(map :db/id))
@@ -700,10 +701,13 @@
ref-pages (filter :block/name refs)
path-ref-pages (->> (concat ref-pages parent-refs [(:db/id page)])
(remove nil?))
block (merge
block
new-block
{:block/path-refs path-ref-pages})]
block (cond->
(merge
block
new-block
{:block/path-refs path-ref-pages})
(> (count blocks) 1)
(assoc :block/warning :multiple-blocks))]
(if uuid (assoc block :block/uuid uuid) block)))))
(defn macro-subs