Parcourir la source

fix: display type blocks in reference

Tienson Qin il y a 1 an
Parent
commit
e0765b4462

+ 60 - 57
src/main/frontend/components/block.cljs

@@ -1118,61 +1118,64 @@
               repo (state/get-current-repo)
               stop-inner-events? (= block-type :whiteboard-shape)]
           (if (and block (:block/title block))
-            (let [title [:span.block-ref
-                         (block-content (assoc config :block-ref? true :stop-events? stop-inner-events?)
-                                        block nil (:block/uuid block)
-                                        (:slide? config))]
-                  inner (cond
-                          label
-                          (->elem
-                           :span.block-ref
-                           (map-inline config label))
-                          :else
-                          title)]
-              [:div.block-ref-wrap.inline
-               {:data-type    (name (or block-type :default))
-                :data-hl-type hl-type
-                :on-pointer-down
-                (fn [^js/MouseEvent e]
-                  (if (util/right-click? e)
-                    (state/set-state! :block-ref/context {:block (:block config)
-                                                          :block-ref block-id})
-                    (when (and
-                           (or (gobj/get e "shiftKey")
-                               (not (.. e -target (closest ".blank"))))
-                           (not (util/right-click? e)))
-                      (util/stop e)
-
-                      (cond
-                        (gobj/get e "shiftKey")
-                        (state/sidebar-add-block!
-                         (state/get-current-repo)
-                         (:db/id block)
-                         :block-ref)
-
-                        (and (util/meta-key? e) (whiteboard-handler/inside-portal? (.-target e)))
-                        (whiteboard-handler/add-new-block-portal-shape!
-                         (:block/uuid block)
-                         (whiteboard-handler/closest-shape (.-target e)))
-
-                        :else
-                        (match [block-type (util/electron?)]
+            (let [content-cp (block-content (assoc config :block-ref? true :stop-events? stop-inner-events?)
+                                            block nil (:block/uuid block)
+                                            (:slide? config))
+                  display-type (:logseq.property.node/display-type block)]
+              (if (and display-type (not (contains? #{:quote :math} display-type)))
+                content-cp
+                (let [title [:span.block-ref content-cp]
+                      inner (cond
+                              label
+                              (->elem
+                               :span.block-ref
+                               (map-inline config label))
+                              :else
+                              title)]
+                  [:div.block-ref-wrap.inline
+                   {:data-type    (name (or block-type :default))
+                    :data-hl-type hl-type
+                    :on-pointer-down
+                    (fn [^js/MouseEvent e]
+                      (if (util/right-click? e)
+                        (state/set-state! :block-ref/context {:block (:block config)
+                                                              :block-ref block-id})
+                        (when (and
+                               (or (gobj/get e "shiftKey")
+                                   (not (.. e -target (closest ".blank"))))
+                               (not (util/right-click? e)))
+                          (util/stop e)
+
+                          (cond
+                            (gobj/get e "shiftKey")
+                            (state/sidebar-add-block!
+                             (state/get-current-repo)
+                             (:db/id block)
+                             :block-ref)
+
+                            (and (util/meta-key? e) (whiteboard-handler/inside-portal? (.-target e)))
+                            (whiteboard-handler/add-new-block-portal-shape!
+                             (:block/uuid block)
+                             (whiteboard-handler/closest-shape (.-target e)))
+
+                            :else
+                            (match [block-type (util/electron?)]
                           ;; pdf annotation
-                          [:annotation true] (pdf-assets/open-block-ref! block)
+                              [:annotation true] (pdf-assets/open-block-ref! block)
 
-                          [:whiteboard-shape true] (route-handler/redirect-to-page!
-                                                    (get-in block [:block/page :block/uuid]) {:block-id block-id})
+                              [:whiteboard-shape true] (route-handler/redirect-to-page!
+                                                        (get-in block [:block/page :block/uuid]) {:block-id block-id})
 
                           ;; default open block page
-                          :else (route-handler/redirect-to-page! id))))))}
-
-               (if (and (not (util/mobile?))
-                        (not (:preview? config))
-                        (not (:modal/show? @state/state))
-                        (nil? block-type))
-                 (block-reference-preview inner
-                                          {:repo repo :config config :id block-id})
-                 inner)])
+                              :else (route-handler/redirect-to-page! id))))))}
+
+                   (if (and (not (util/mobile?))
+                            (not (:preview? config))
+                            (not (:modal/show? @state/state))
+                            (nil? block-type))
+                     (block-reference-preview inner
+                                              {:repo repo :config config :id block-id})
+                     inner)])))
             (invalid-node-ref id))))
       (invalid-node-ref id))))
 
@@ -1798,7 +1801,7 @@
     ["Latex_Fragment" [display s]] ;display can be "Displayed" or "Inline"
     (if html-export?
       (latex/html-export s false true)
-      (latex/latex (str (d/squuid)) s false (not= display "Inline")))
+      (latex/latex s false (not= display "Inline")))
 
     [(:or "Target" "Radio_Target") s]
     [:a {:id s} s]
@@ -2203,7 +2206,7 @@
 
       ;; TODO: switched to https://cortexjs.io/mathlive/ for editing
       (= :math node-display-type)
-      (latex/latex (str (:container-id config) "-" (:db/id block)) (:block/title block) true false)
+      (latex/latex (:block/title block) true false)
 
       (and query?
            collapsed?
@@ -3753,7 +3756,7 @@
       ["Math" s]
       (if html-export?
         (latex/html-export s true true)
-        (latex/latex (str (d/squuid)) s true true))
+        (latex/latex s true true))
       ["Example" l]
       [:pre.pre-wrap-white-space
        (join-lines l)]
@@ -3783,7 +3786,7 @@
         (latex/html-export content true false)
         (if (config/db-based-graph? (state/get-current-repo))
           [:div.warning "'#+BEGIN_EXPORT latex' is deprecated. Use '/Math block' command instead."]
-          (latex/latex (str (d/squuid)) content true false)))
+          (latex/latex content true false)))
 
       ["Custom" "query" _options _result content]
       (if (config/db-based-graph? (state/get-current-repo))
@@ -3832,12 +3835,12 @@
       (let [content (latex-environment-content name option content)]
         (if html-export?
           (latex/html-export content true true)
-          (latex/latex (str (d/squuid)) content true true)))
+          (latex/latex content true true)))
 
       ["Displayed_Math" content]
       (if html-export?
         (latex/html-export content true true)
-        (latex/latex (str (d/squuid)) content true true))
+        (latex/latex content true true))
 
       ["Footnote_Definition" name definition]
       (let [id (util/url-encode name)]

+ 2 - 3
src/main/frontend/components/shortcut_help.cljs

@@ -75,7 +75,7 @@
                   :link [:a {:href "https://www.example.com"} "Link"]
                   :del [:del (t :strikethrough)]
                   :mark [:mark (t :highlight)]
-                  :latex (latex/latex "help-latex" "E = mc^2" true false)
+                  :latex (latex/latex "E = mc^2" true false)
                   :code [:code (t :code)]
                   :pre (highlight/highlight "help-highlight" {:data-lang "clojure"} "(println \"Hello world!\")")
                   :img [:img {:style {:float "right" :width 32 :height 32}
@@ -92,8 +92,7 @@
              [:tr
               [:td.text-left [(if (= :pre name) :pre :code) (get raw name)]]
               [:td.text-right (get rendered name)]])
-        list)]]))
-
+           list)]]))
 
 (rum/defc shortcut-page
   [{:keys [show-title?]

+ 9 - 5
src/main/frontend/extensions/latex.cljs

@@ -16,7 +16,8 @@
 
 (defn render!
   [state]
-  (let [[id s _ display?] (:rum/args state)]
+  (let [[s _ display?] (:rum/args state)
+        id (:id state)]
     (try
       (when-let [elem (gdom/getElement id)]
         (js/katex.render s elem
@@ -56,11 +57,14 @@
   (js/setTimeout #(load-and-render! state) 10)
   state)
 
-(rum/defc latex < rum/reactive
-  {:did-mount  state-&-load-and-render!
+(rum/defcs latex < rum/reactive
+  {:init (fn [state]
+           (assoc state :id (str (random-uuid))))
+   :did-mount  state-&-load-and-render!
    :did-update state-&-load-and-render!}
-  [id s block? _display?]
-  (let [loading? (rum/react *loading?)]
+  [state s block? _display?]
+  (let [id (:id state)
+        loading? (rum/react *loading?)]
     (if loading?
       (ui/loading)
       (let [element (if block?