fix: can't paste multi-line block using github's code block

This commit is contained in:
Tienson Qin
2023-04-18 23:19:23 +08:00
parent 56074732f2
commit a7dfb37055

View File

@@ -15,7 +15,6 @@
[frontend.util.thingatpt :as thingatpt]
["/frontend/utils" :as utils]
[frontend.commands :as commands]
[cljs.core.match :refer [match]]
[frontend.util.text :as text-util]
[frontend.format.mldoc :as mldoc]
[lambdaisland.glogi :as log]
@@ -96,6 +95,14 @@
(when blocks-str
(gp-util/safe-read-string blocks-str))))
(defn- markdown-blocks?
[text]
(util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
(defn- org-blocks?
[text]
(util/safe-re-find #"(?m)^\s*\*+\s+" text))
(defn- paste-copied-blocks-or-text
;; todo: logseq/whiteboard-shapes is now text/html
[text e html]
@@ -147,28 +154,18 @@
(log/error :exception e)
nil)))]
(if (string/blank? result) nil result))
text (or html-text text)]
(match [format
(nil? (util/safe-re-find #"(?m)^\s*(?:[-+*]|#+)\s+" text))
(nil? (util/safe-re-find #"(?m)^\s*\*+\s+" text))
(nil? (util/safe-re-find #"(?:\r?\n){2,}" text))]
[:markdown false _ _]
text-blocks? (if (= format :markdown) markdown-blocks? org-blocks?)
blocks? (text-blocks? text)
text' (or html-text text)]
(cond
blocks?
(paste-text-parseable format text)
[:org _ false _]
(paste-text-parseable format text)
(util/safe-re-find #"(?:\r?\n){2,}" text')
(paste-segmented-text format text')
[:markdown true _ false]
(paste-segmented-text format text)
[:markdown true _ true]
(replace-text-f text)
[:org _ true false]
(paste-segmented-text format text)
[:org _ true true]
(replace-text-f text))))))))
:else
(replace-text-f text'))))))))
(p/catch (fn [error]
(prn "Paste failed: ")
(log/error :exception error)))))