Browse Source

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

or headings.
Tienson Qin 4 years ago
parent
commit
ad7de321e0

+ 6 - 1
src/main/frontend/components/block.cljs

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

+ 1 - 0
src/main/frontend/db_schema.cljs

@@ -145,6 +145,7 @@
     :block/properties
     :block/created-at
     :block/updated-at
+    :block/warning
     }
   )
 

+ 10 - 6
src/main/frontend/format/block.cljs

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