Skip to content

Commit

Permalink
enhance: display a warning if a block's content include multiple lists
Browse files Browse the repository at this point in the history
or headings.
  • Loading branch information
tiensonqin committed Nov 17, 2021
1 parent 1f77977 commit ad7de32
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/main/frontend/components/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,12 @@
(for [[idx child] (medley/indexed body)]
(when-let [block (markup-element-cp config child)]
(rum/with-key (block-child block)
(str uuid "-" idx)))))])]]]))
(str uuid "-" idx)))))])

(case (:block/warning block)
:multiple-blocks
[:p.warning.text-sm "Full content is not displayed, Logseq doesn't support multiple unordered lists or headings in a block."]
nil)]]]))

(rum/defc block-refs-count < rum/reactive
[block]
Expand Down
1 change: 1 addition & 0 deletions src/main/frontend/db_schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
:block/properties
:block/created-at
:block/updated-at
:block/warning
}
)

Expand Down
16 changes: 10 additions & 6 deletions src/main/frontend/format/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -688,22 +688,26 @@
([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))
{:block/keys [refs]} new-block
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
Expand Down

0 comments on commit ad7de32

Please sign in to comment.