Parcourir la source

feat: add embed pages to references and graph view

Resolved https://github.com/logseq/logseq/issues/166.
Tienson Qin il y a 5 ans
Parent
commit
e53d4cdd47
1 fichiers modifiés avec 52 ajouts et 28 suppressions
  1. 52 28
      src/main/frontend/format/block.cljs

+ 52 - 28
src/main/frontend/format/block.cljs

@@ -24,37 +24,61 @@
 
 (defn get-page-reference
   [block]
-  (cond
-    (and (vector? block) (= "Link" (first block)))
-    (let [typ (first (:url (second block)))]
-      (or
-       (and
-        (= typ "Search")
-        (not (contains? #{\# \* \/ \( \[} (first (second (:url (second block))))))
-        (let [page (second (:url (second block)))]
-          (when (and (not (util/starts-with? page "http"))
-                     (not (util/starts-with? page "file"))
-                     (not (string/ends-with? page ".html")))
-            page)))
-
-       (and
-        (= typ "Complex")
-        (= (:protocol (second (:url (second block)))) "file")
-        (:link (second (:url (second block)))))))
-
-    (and (vector? block) (= "Nested_link" (first block)))
-    (let [content (:content (last block))]
-      (subs content 2 (- (count content) 2)))
-
-    :else
-    nil))
+  (let [page (cond
+               (and (vector? block) (= "Link" (first block)))
+               (let [typ (first (:url (second block)))]
+                 (or
+                  (and
+                   (= typ "Search")
+                   (not (contains? #{\# \* \/ \( \[} (first (second (:url (second block))))))
+                   (let [page (second (:url (second block)))]
+                     (when (and (not (util/starts-with? page "http"))
+                                (not (util/starts-with? page "file"))
+                                (not (string/ends-with? page ".html")))
+                       page)))
+
+                  (and
+                   (= typ "Complex")
+                   (= (:protocol (second (:url (second block)))) "file")
+                   (:link (second (:url (second block)))))))
+
+               (and (vector? block) (= "Nested_link" (first block)))
+               (let [content (:content (last block))]
+                 (subs content 2 (- (count content) 2)))
+
+               (and (vector? block)
+                    (= "Macro" (first block)))
+               (let [{:keys [name arguments]} (second block)]
+                 (when (and (= name "embed")
+                            (string? (first arguments))
+                            (string/starts-with? (first arguments) "[[")
+                            (string/ends-with? (first arguments) "]]"))
+                   (subs (first arguments) 2 (- (count (first arguments)) 2))))
+               :else
+               nil)]
+    (when-not (string/blank? page)
+      (string/trim page))))
 
 (defn get-block-reference
   [block]
-  (when-let [block-id (and (vector? block)
-                           (= "Block_reference" (first block))
-                           (last block))]
-    (when (util/uuid-string? block-id)
+  (when-let [block-id (cond
+                        (and (vector? block)
+                             (= "Block_reference" (first block)))
+                        (last block)
+
+                        (and (vector? block)
+                             (= "Macro" (first block)))
+                        (let [{:keys [name arguments]} (second block)]
+                          (when (and (= name "embed")
+                                     (string? (first arguments))
+                                     (string/starts-with? (first arguments) "((")
+                                     (string/ends-with? (first arguments) "))"))
+                            (subs (first arguments) 2 (- (count (first arguments)) 2))))
+
+                        :else
+                        nil)]
+    (when (and block-id
+               (util/uuid-string? block-id))
       block-id)))
 
 ;; FIXME: