Browse Source

Enable mldoc/link?

Gabriel Horner 3 years ago
parent
commit
4ff4d579bf

+ 1 - 2
src/main/logseq/graph_parser/block.cljs

@@ -165,8 +165,7 @@
                      (map last)
                      (map (fn [v]
                             (when (and (string? v)
-                                       ;; TODO: Enable mldoc-link?
-                                       #_(not (mldoc/link? format v)))
+                                       (not (mldoc/link? format v)))
                               (let [v (string/trim v)
                                     result (text/split-page-refs-without-brackets v {:un-brackets? false})]
                                 (if (coll? result)

+ 28 - 27
src/main/logseq/graph_parser/mldoc.cljs

@@ -223,16 +223,16 @@
 ;       (log/error :edn/convert-failed e)
 ;       [])))
 ;
-; (defn inline->edn
-;   [text config]
-;   (try
-;     (if (string/blank? text)
-;       {}
-;       (-> text
-;           (inline-parse-json config)
-;           (util/json->clj)))
-;     (catch js/Error _e
-;       [])))
+(defn inline->edn
+  [text config]
+  (try
+    (if (string/blank? text)
+      {}
+      (-> text
+          (inline-parse-json config)
+          (util/json->clj)))
+    (catch js/Error _e
+      [])))
 ;
 ; (defrecord MldocMode []
 ;   protocol/Format
@@ -262,20 +262,21 @@
 ;   (and (contains? #{"Drawer"} (ffirst ast))
 ;        (= typ (second (first ast)))))
 ;
-; (defn link?
-;   [format link]
-;   (when (string? link)
-;     (let [[type link] (first (inline->edn link (default-config format)))
-;           [ref-type ref-value] (:url link)]
-;       (and (= "Link" type)
-;            (or
-;             ;; 1. url
-;             (not (contains? #{"Page_ref" "Block_ref"} ref-type))
-;
-;             (and (contains? #{"Page_ref"} ref-type)
-;                  (or
-;                   ;; 2. excalidraw link
-;                   (config/draw? ref-value)
-;
-;                   ;; 3. local asset link
-;                   (boolean (config/local-asset? ref-value)))))))))
+(defn link?
+  [format link]
+  (when (string? link)
+    (let [[type link] (first (inline->edn link (default-config format)))
+          [ref-type ref-value] (:url link)]
+      (and (= "Link" type)
+           (or
+            ;; 1. url
+            (not (contains? #{"Page_ref" "Block_ref"} ref-type))
+
+            (and (contains? #{"Page_ref"} ref-type)
+                 ;; TODO: Pull in config
+                 #_(or
+                    ;; 2. excalidraw link
+                    (config/draw? ref-value)
+
+                    ;; 3. local asset link
+                    (boolean (config/local-asset? ref-value)))))))))

+ 3 - 4
src/main/logseq/graph_parser/text.cljs

@@ -4,7 +4,7 @@
             ; ["/frontend/utils" :as utils]
             [goog.string :as gstring]
             [clojure.string :as string]
-            ; [frontend.format.mldoc :as mldoc]
+            [logseq.graph-parser.mldoc :as mldoc]
             [clojure.set :as set]))
 
 (def page-ref-re-0 #"\[\[(.*)\]\]")
@@ -372,9 +372,8 @@
        (contains? @non-parsing-properties (string/lower-case k))
        v
 
-       ;; TODO: Enable mldoc/link?
-       ; (mldoc/link? format v)
-       ; v
+       (mldoc/link? format v)
+       v
 
        :else
        (split-page-refs-without-brackets v)))))