|
|
@@ -8,6 +8,7 @@
|
|
|
["mldoc" :as mldoc :refer [Mldoc]]
|
|
|
[logseq.graph-parser.mldoc :as gp-mldoc]
|
|
|
[logseq.graph-parser.util :as gp-util]
|
|
|
+ [logseq.graph-parser.text :as text]
|
|
|
[clojure.walk :as walk]))
|
|
|
|
|
|
(defonce anchorLink (gobj/get Mldoc "anchorLink"))
|
|
|
@@ -92,3 +93,41 @@
|
|
|
f))
|
|
|
ast)
|
|
|
@*result))
|
|
|
+
|
|
|
+(defn extract-plain
|
|
|
+ "Extract plain elements including page refs"
|
|
|
+ [content]
|
|
|
+ (let [ast (->edn content (gp-mldoc/default-config :markdown))]
|
|
|
+ (let [*result (atom [])]
|
|
|
+ (walk/prewalk
|
|
|
+ (fn [f]
|
|
|
+ (cond
|
|
|
+ ;; tag
|
|
|
+ (and (vector? f)
|
|
|
+ (= "Tag" (first f)))
|
|
|
+ nil
|
|
|
+
|
|
|
+ ;; nested page ref
|
|
|
+ (and (vector? f)
|
|
|
+ (= "Nested_link" (first f)))
|
|
|
+ (swap! *result conj (:content (second f)))
|
|
|
+
|
|
|
+ ;; page ref
|
|
|
+ (and (vector? f)
|
|
|
+ (= "Link" (first f))
|
|
|
+ (map? (second f))
|
|
|
+ (vector? (:url (second f)))
|
|
|
+ (= "Page_ref" (first (:url (second f)))))
|
|
|
+ (swap! *result conj
|
|
|
+ (:full_text (second f)))
|
|
|
+
|
|
|
+ ;; plain
|
|
|
+ (and (vector? f)
|
|
|
+ (= "Plain" (first f)))
|
|
|
+ (swap! *result conj (second f))
|
|
|
+
|
|
|
+ :else
|
|
|
+ f))
|
|
|
+ ast)
|
|
|
+ (-> (string/trim (apply str @*result))
|
|
|
+ text/page-ref-un-brackets!))))
|