fix: use mldoc to check links

pull/8575/head
Tienson Qin 2023-02-13 15:17:46 +08:00
parent 9f2ce3dd39
commit c8db7646e2
3 changed files with 11 additions and 7 deletions

View File

@ -164,3 +164,13 @@
(when (string? link)
(some-> (first (inline->edn link (default-config format)))
ast-link?)))
(defn mldoc-link?
"Check whether s is a link (including page/block refs)."
[format s]
(let [result (inline->edn s (default-config format))]
(and
(= 1 (count result))
(let [result' (first result)]
(or (contains? #{"Nested_link"} (first result'))
(contains? #{"Page_ref" "Block_ref" "Complex"} (first (:url (second result')))))))))

View File

@ -88,12 +88,6 @@
(catch :default _e
false))))
(defn link?
"Check whether s is a link (including page/block refs)."
[s]
(or (url? s)
(re-matches #"^(\[\[|\(\().*(\]\]|\)\))$" (string/trim s))))
(defn json->clj
[json-string]
(-> json-string

View File

@ -131,7 +131,7 @@
(let [{:keys [selection-start selection-end format selection value edit-id input]} m
cur-pos (cursor/pos input)
empty-selection? (= selection-start selection-end)
selection-link? (and selection (gp-util/link? selection))
selection-link? (and selection (gp-mldoc/mldoc-link? format selection))
[content forward-pos] (cond
empty-selection?
(config/get-empty-link-and-forward-pos format)