Просмотр исходного кода

Add show ast at block and page level

Gabriel Horner 2 лет назад
Родитель
Сommit
1b1e68d8ac

+ 25 - 3
src/main/frontend/components/content.cljs

@@ -20,6 +20,7 @@
             [frontend.util :as util]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util.block-ref :as block-ref]
+            [logseq.graph-parser.mldoc :as gp-mldoc]
             [frontend.util.url :as url-util]
             [goog.dom :as gdom]
             [goog.object :as gobj]
@@ -168,8 +169,8 @@
             :icon "h-auto"
             :icon-props {:extension? true}
             :class "to-heading-button"
-            :title (if (= format :markdown) 
-                     (str (t :auto-heading) " - " (t :not-available-in-mode format)) 
+            :title (if (= format :markdown)
+                     (str (t :auto-heading) " - " (t :not-available-in-mode format))
                      (t :auto-heading))
             :disabled (= format :markdown)
             :on-click (fn [_e]
@@ -212,7 +213,7 @@
           (t :content/copy-block-emebed)
           nil)
 
-          ;; TODO Logseq protocol mobile support
+         ;; TODO Logseq protocol mobile support
          (when (util/electron?)
            (ui/menu-link
             {:key      "Copy block URL"
@@ -305,6 +306,27 @@
                             :success
                             false)))}
             "(Dev) Show block data"
+            nil))
+  
+         (when (state/sub [:ui/developer-mode?])
+           (ui/menu-link
+            {:key      "(Dev) Show block AST"
+             :on-click (fn []
+                         (let [block (db/pull [:block/uuid block-id])
+                               block-data (-> (gp-mldoc/->edn (:block/content block)
+                                                              (gp-mldoc/default-config (:block/format block)))
+                                              pprint/pprint
+                                              with-out-str)]
+                           (println block-data)
+                           (notification/show!
+                            [:div
+                             [:pre.code block-data]
+                             [:br]
+                             (ui/button "Copy to clipboard"
+                                        :on-click #(.writeText js/navigator.clipboard block-data))]
+                            :success
+                            false)))}
+            "(Dev) Show block AST"
             nil))])))
 
 (rum/defc block-ref-custom-context-menu-content

+ 22 - 2
src/main/frontend/components/page_menu.cljs

@@ -16,7 +16,8 @@
             [electron.ipc :as ipc]
             [frontend.config :as config]
             [frontend.handler.user :as user-handler]
-            [frontend.handler.file-sync :as file-sync-handler]))
+            [frontend.handler.file-sync :as file-sync-handler]
+            [logseq.graph-parser.mldoc :as gp-mldoc]))
 
 (defn- delete-page!
   [page-name]
@@ -113,7 +114,7 @@
             {:title   (t :page/delete)
              :options {:on-click #(state/set-modal! (delete-page-dialog page-name))}})
 
-          (when (and (not (mobile-util/native-platform?)) 
+          (when (and (not (mobile-util/native-platform?))
                      (state/get-current-page))
             {:title (t :page/presentation-mode)
              :options {:on-click (fn []
@@ -173,6 +174,25 @@
                                         "Copy to clipboard"
                                         :on-click #(.writeText js/navigator.clipboard page-data))]
                                       :success
+                                      false)))}})
+
+          (when developer-mode?
+            {:title   "(Dev) Show page AST"
+             :options {:on-click (fn []
+                                   (let [page (db/pull '[:block/format {:block/file [:file/content]}] (:db/id page))
+                                         page-data (-> (gp-mldoc/->edn (get-in page [:block/file :file/content])
+                                                                       (gp-mldoc/default-config (:block/format page)))
+                                                       pprint/pprint
+                                                       with-out-str)]
+                                     (println page-data)
+                                     (notification/show!
+                                      [:div
+                                       (ui/button
+                                        "Copy to clipboard"
+                                        :on-click #(.writeText js/navigator.clipboard page-data))
+                                       [:br]
+                                       [:pre.code page-data]]
+                                      :success
                                       false)))}})]
          (flatten)
          (remove nil?))))))