Pārlūkot izejas kodu

update inline.link type

related to https://github.com/logseq/mldoc/pull/70
rcmerci 4 gadi atpakaļ
vecāks
revīzija
1a547e944d

+ 12 - 12
src/main/frontend/components/block.cljs

@@ -672,7 +672,7 @@
     ["Subscript" l]
     (->elem :sub (map-inline config l))
     ["Tag" s]
-    (when s
+    (when-let [s (block/get-tag item)]
       (let [s (text/page-ref-un-brackets! s)]
         [:a.tag {:data-ref s
                  :href (rfe/href :page {:name s})
@@ -722,9 +722,9 @@
       [:a {:href (str "mainto:" address)}
        address])
 
-    ["Block_reference" id]
-    ;; FIXME: alert when self block reference
-    (block-reference (assoc config :reference? true) id nil)
+    ;; ["Block_reference" id]
+    ;; ;; FIXME: alert when self block reference
+    ;; (block-reference (assoc config :reference? true) id nil)
 
     ["Nested_link" link]
     (nested-link config html-export? link)
@@ -732,19 +732,19 @@
     ["Link" link]
     (let [{:keys [url label title metadata full_text]} link]
       (match url
+        ["Block_ref" id]
+        (let [label* (if (seq (mldoc/plain->text label)) label nil)]
+          (block-reference (assoc config :reference? true) id label*))
+
+        ["Page_ref" page]
+        (let [label* (if (seq (mldoc/plain->text label)) label nil)]
+          (page-reference (:html-export? config) page config label*))
+
         ["Search" s]
         (cond
           (string/blank? s)
           [:span.warning {:title "Invalid link"} full_text]
 
-          (text/block-ref? s)
-          (let [block-id (text/block-ref-un-brackets! s)]
-            (block-reference config block-id label))
-
-          (text/page-ref? s)
-          (let [page (text/page-ref-un-brackets! s)]
-            (page-reference (:html-export? config) page config label))
-
           (= \# (first s))
           (->elem :a {:on-click #(route-handler/jump-to-anchor! (mldoc/anchorLink (subs s 1)))} (subs s 1))
 

+ 30 - 3
src/main/frontend/format/block.cljs

@@ -1,6 +1,7 @@
 (ns frontend.format.block
   (:require [clojure.string :as string]
             [clojure.walk :as walk]
+            [cljs.core.match :refer [match]]
             [frontend.config :as config]
             [frontend.date :as date]
             [frontend.db :as db]
@@ -21,9 +22,24 @@
 
 (defn get-tag
   [block]
-  (and (vector? block)
-       (= "Tag" (first block))
-       (second block)))
+  (when-let [tag-value (and (vector? block)
+                            (= "Tag" (first block))
+                            (second block))]
+    (->
+     (mapv (fn [e]
+             (match e
+                    ["Plain" s]
+                    s
+                    ["Link" t]
+                    (let [{full_text :full_text} t]
+                      full_text)
+                    ["Nested_link" t]
+                    (let [ {content :content} t]
+                      content)
+                    :else
+                    ""
+                    )) tag-value)
+     (string/join))))
 
 (defn get-page-reference
   [block]
@@ -32,6 +48,11 @@
                (let [typ (first (:url (second block)))]
                  ;; {:url ["File" "file:../pages/hello_world.org"], :label [["Plain" "hello world"]], :title nil}
                  (or
+                  (and
+                   (= typ "Page_ref")
+                   (string? (second (:url (second block))))
+                   (second (:url (second block))))
+
                   (and
                    (= typ "Search")
                    (string? (second (:url (second block))))
@@ -103,6 +124,12 @@
                              (= "Block_reference" (first block)))
                         (last block)
 
+                        (and (vector? block)
+                             (= "Link" (first block))
+                             (map? (second block))
+                             (= "Block_ref" (first (:url (second block)))))
+                        (second (:url (second block)))
+
                         (and (vector? block)
                              (= "Macro" (first block)))
                         (let [{:keys [name arguments]} (second block)]