fix(properties): use simpler regexp for urls

pull/3536/head
Andelf 2021-12-19 21:47:32 +08:00 committed by Tienson Qin
parent 19cbd3d61b
commit 66c8154ef3
1 changed files with 15 additions and 19 deletions

View File

@ -1,8 +1,7 @@
(ns frontend.handler.link
(:require
[frontend.util :as util]))
(:require [frontend.util :as util]))
(def plain-link "(?:http://www\\.|https://www\\.|http://|https://){1}[a-z0-9]+(?:[\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(?:.*)*")
(def plain-link "(\b(https?|file)://)?[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]")
(def plain-link-re (re-pattern plain-link))
(def org-link-re-1 (re-pattern (util/format "\\[\\[(%s)\\]\\[(.+)\\]\\]" plain-link)))
(def org-link-re-2 (re-pattern (util/format "\\[\\[(%s)\\]\\]" plain-link)))
@ -10,27 +9,24 @@
(defn- plain-link?
[link]
(let [matches (re-matches plain-link-re link)]
(when matches
(when-let [matches (re-matches plain-link-re link)]
{:type "plain-link"
:url matches})))
:url matches}))
(defn- org-link?
[link]
(let [matches (or (re-matches org-link-re-1 link)
(when-let [matches (or (re-matches org-link-re-1 link)
(re-matches org-link-re-2 link))]
(when matches
{:type "org-link"
:url (second matches)
:label (nth matches 2 nil)})))
:label (nth matches 2 nil)}))
(defn- markdown-link?
[link]
(let [matches (re-matches markdown-link-re link)]
(when matches
(when-let [matches (re-matches markdown-link-re link)]
{:type "markdown-link"
:url (nth matches 2)
:label (second matches)})))
:label (second matches)}))
(defn link?
[link]