Merge pull request #5265 from logseq/enhance/graph-parser-part-two

Enhance: Migrate mldoc and text to graph-parser
This commit is contained in:
Tienson Qin
2022-05-12 20:22:51 +08:00
committed by GitHub
46 changed files with 618 additions and 482 deletions

View File

@@ -34,8 +34,8 @@
[frontend.search :as search]
[frontend.state :as state]
[frontend.template :as template]
[frontend.text :as text]
[frontend.utf8 :as utf8]
[logseq.graph-parser.text :as text]
[logseq.graph-parser.utf8 :as utf8]
[frontend.util :as util :refer [profile]]
[frontend.util.clock :as clock]
[frontend.util.cursor :as cursor]
@@ -53,6 +53,7 @@
[promesa.core :as p]
[frontend.util.keycode :as keycode]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.mldoc :as gp-mldoc]
["path" :as path]))
;; FIXME: should support multiple images concurrently uploading
@@ -356,7 +357,7 @@
content (drawer/with-logbook block content)
content (with-timetracking block content)
first-block? (= left page)
ast (mldoc/->edn (string/trim content) (mldoc/default-config format))
ast (mldoc/->edn (string/trim content) (gp-mldoc/default-config format))
first-elem-type (first (ffirst ast))
first-elem-meta (second (ffirst ast))
properties? (contains? #{"Property_Drawer" "Properties"} first-elem-type)
@@ -1315,7 +1316,7 @@
(defn- clean-content!
[format content]
(->> (text/remove-level-spaces content format)
(->> (text/remove-level-spaces content format (config/get-block-pattern format))
(drawer/remove-logbook)
(property/remove-properties format)
string/trim))
@@ -1943,7 +1944,7 @@
props (into [] (:properties block))
content* (str (if (= :markdown format) "- " "* ")
(property/insert-properties format content props))
ast (mldoc/->edn content* (mldoc/default-config format))
ast (mldoc/->edn content* (gp-mldoc/default-config format))
blocks (block/extract-blocks ast content* true format)
fst-block (first blocks)]
(assert fst-block "fst-block shouldn't be nil")
@@ -2852,7 +2853,7 @@
(when-let [editing-block (state/get-edit-block)]
(let [page-id (:db/id (:block/page editing-block))
blocks (block/extract-blocks
(mldoc/->edn text (mldoc/default-config format)) text true format)
(mldoc/->edn text (gp-mldoc/default-config format)) text true format)
blocks' (block/with-parent-and-left page-id blocks)]
(paste-blocks blocks' {}))))
@@ -2905,17 +2906,17 @@
(state/set-copied-full-blocks! blocks)
(paste-blocks blocks {})))
(and (util/url? text)
(and (gp-util/url? text)
(not (string/blank? (util/get-selected-text))))
(html-link-format! text)
(and (util/url? text)
(and (gp-util/url? text)
(or (string/includes? text "youtube.com")
(string/includes? text "youtu.be"))
(mobile-util/is-native-platform?))
(commands/simple-insert! (state/get-edit-input-id) (util/format "{{youtube %s}}" text) nil)
(and (util/url? text)
(and (gp-util/url? text)
(string/includes? text "twitter.com")
(mobile-util/is-native-platform?))
(commands/simple-insert! (state/get-edit-input-id) (util/format "{{twitter %s}}" text) nil)
@@ -3172,7 +3173,7 @@
[format content semantic?]
(and (string/includes? content "\n")
(if semantic?
(let [ast (mldoc/->edn content (mldoc/default-config format))
(let [ast (mldoc/->edn content (gp-mldoc/default-config format))
first-elem-type (first (ffirst ast))]
(mldoc/block-with-title? first-elem-type))
true)))