Skip to content

Commit

Permalink
fix(properties): use simpler regexp for urls
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf authored and tiensonqin committed Dec 21, 2021
1 parent 19cbd3d commit 66c8154
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/main/frontend/handler/link.cljs
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
(ns frontend.handler.link
(:require
[frontend.util :as util]))
(ns frontend.handler.link
(: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)))
(def markdown-link-re (re-pattern (util/format "^\\[(.+)\\]\\((%s)\\)" plain-link)))

(defn- plain-link?
[link]
(let [matches (re-matches plain-link-re link)]
(when matches
{:type "plain-link"
:url matches})))
(when-let [matches (re-matches plain-link-re link)]
{:type "plain-link"
:url matches}))

(defn- org-link?
[link]
(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)})))
(when-let [matches (or (re-matches org-link-re-1 link)
(re-matches org-link-re-2 link))]
{:type "org-link"
:url (second matches)
:label (nth matches 2 nil)}))

(defn- markdown-link?
[link]
(let [matches (re-matches markdown-link-re link)]
(when matches
{:type "markdown-link"
:url (nth matches 2)
:label (second matches)})))
(when-let [matches (re-matches markdown-link-re link)]
{:type "markdown-link"
:url (nth matches 2)
:label (second matches)}))

(defn link?
[link]
Expand Down

0 comments on commit 66c8154

Please sign in to comment.