|
@@ -51,8 +51,6 @@
|
|
|
|
|
|
(def page-ref-re-without-nested #"\[\[([^\[\]]+)\]\]")
|
|
(def page-ref-re-without-nested #"\[\[([^\[\]]+)\]\]")
|
|
|
|
|
|
-(defonce between-re #"\(between ([^\)]+)\)")
|
|
|
|
-
|
|
|
|
(defn page-ref-un-brackets!
|
|
(defn page-ref-un-brackets!
|
|
[s]
|
|
[s]
|
|
(or (get-page-name s) s))
|
|
(or (get-page-name s) s))
|
|
@@ -122,18 +120,6 @@
|
|
[s]
|
|
[s]
|
|
(string/split s #"(\"[^\"]*\")"))
|
|
(string/split s #"(\"[^\"]*\")"))
|
|
|
|
|
|
-(def bilibili-regex #"^((?:https?:)?//)?((?:www).)?((?:bilibili.com))(/(?:video/)?)([\w-]+)(\S+)?$")
|
|
|
|
-(def loom-regex #"^((?:https?:)?//)?((?:www).)?((?:loom.com))(/(?:share/|embed/))([\w-]+)(\S+)?$")
|
|
|
|
-(def vimeo-regex #"^((?:https?:)?//)?((?:www).)?((?:player.vimeo.com|vimeo.com))(/(?:video/)?)([\w-]+)(\S+)?$")
|
|
|
|
-(def youtube-regex #"^((?:https?:)?//)?((?:www|m).)?((?:youtube.com|youtu.be|y2u.be|youtube-nocookie.com))(/(?:[\w-]+\?v=|embed/|v/)?)([\w-]+)([\S^\?]+)?$")
|
|
|
|
-
|
|
|
|
-(defn get-matched-video
|
|
|
|
- [url]
|
|
|
|
- (or (re-find youtube-regex url)
|
|
|
|
- (re-find loom-regex url)
|
|
|
|
- (re-find vimeo-regex url)
|
|
|
|
- (re-find bilibili-regex url)))
|
|
|
|
-
|
|
|
|
(def markdown-link #"\[([^\[]+)\](\(.*\))")
|
|
(def markdown-link #"\[([^\[]+)\](\(.*\))")
|
|
|
|
|
|
(defn split-page-refs-without-brackets
|
|
(defn split-page-refs-without-brackets
|
|
@@ -228,16 +214,6 @@
|
|
:else
|
|
:else
|
|
(remove-level-space-aux! text block-pattern space? trim-left?)))))
|
|
(remove-level-space-aux! text block-pattern space? trim-left?)))))
|
|
|
|
|
|
-(defn build-data-value
|
|
|
|
- [col]
|
|
|
|
- (let [items (map (fn [item] (str "\"" item "\"")) col)]
|
|
|
|
- (gstring/format "[%s]"
|
|
|
|
- (string/join ", " items))))
|
|
|
|
-
|
|
|
|
-(defn media-link?
|
|
|
|
- [media-formats s]
|
|
|
|
- (some (fn [fmt] (gp-util/safe-re-find (re-pattern (str "(?i)\\." fmt "(?:\\?([^#]*))?(?:#(.*))?$")) s)) media-formats))
|
|
|
|
-
|
|
|
|
(defn namespace-page?
|
|
(defn namespace-page?
|
|
[p]
|
|
[p]
|
|
(and (string? p)
|
|
(and (string? p)
|
|
@@ -246,100 +222,6 @@
|
|
(not (string/starts-with? p "./"))
|
|
(not (string/starts-with? p "./"))
|
|
(not (gp-util/url? p))))
|
|
(not (gp-util/url? p))))
|
|
|
|
|
|
-(defn add-timestamp
|
|
|
|
- [content key value]
|
|
|
|
- (let [new-line (str (string/upper-case key) ": " value)
|
|
|
|
- lines (string/split-lines content)
|
|
|
|
- new-lines (map (fn [line]
|
|
|
|
- (string/trim
|
|
|
|
- (if (string/starts-with? (string/lower-case line) key)
|
|
|
|
- new-line
|
|
|
|
- line)))
|
|
|
|
- lines)
|
|
|
|
- new-lines (if (not= (map string/trim lines) new-lines)
|
|
|
|
- new-lines
|
|
|
|
- (cons (first new-lines) ;; title
|
|
|
|
- (cons
|
|
|
|
- new-line
|
|
|
|
- (rest new-lines))))]
|
|
|
|
- (string/join "\n" new-lines)))
|
|
|
|
-
|
|
|
|
-(defn remove-timestamp
|
|
|
|
- [content key]
|
|
|
|
- (let [lines (string/split-lines content)
|
|
|
|
- new-lines (filter (fn [line]
|
|
|
|
- (not (string/starts-with? (string/lower-case line) key)))
|
|
|
|
- lines)]
|
|
|
|
- (string/join "\n" new-lines)))
|
|
|
|
-
|
|
|
|
-(defn get-current-line-by-pos
|
|
|
|
- [s pos]
|
|
|
|
- (let [lines (string/split-lines s)
|
|
|
|
- result (reduce (fn [acc line]
|
|
|
|
- (let [new-pos (+ acc (count line))]
|
|
|
|
- (if (>= new-pos pos)
|
|
|
|
- (reduced line)
|
|
|
|
- (inc new-pos)))) 0 lines)]
|
|
|
|
- (when (string? result)
|
|
|
|
- result)))
|
|
|
|
-
|
|
|
|
-(defn get-string-all-indexes
|
|
|
|
- "Get all indexes of `value` in the string `s`."
|
|
|
|
- [s value]
|
|
|
|
- (loop [acc []
|
|
|
|
- i 0]
|
|
|
|
- (if-let [i (string/index-of s value i)]
|
|
|
|
- (recur (conj acc i) (+ i (count value)))
|
|
|
|
- acc)))
|
|
|
|
-
|
|
|
|
-(defn surround-by?
|
|
|
|
- "`pos` must be surrounded by `before` and `and` in string `value`, e.g. ((|))"
|
|
|
|
- [value pos before end]
|
|
|
|
- (let [start-pos (if (= :start before) 0 (- pos (count before)))
|
|
|
|
- end-pos (if (= :end end) (count value) (+ pos (count end)))]
|
|
|
|
- (when (>= (count value) end-pos)
|
|
|
|
- (= (cond
|
|
|
|
- (and (= :end end) (= :start before))
|
|
|
|
- ""
|
|
|
|
-
|
|
|
|
- (= :end end)
|
|
|
|
- before
|
|
|
|
-
|
|
|
|
- (= :start before)
|
|
|
|
- end
|
|
|
|
-
|
|
|
|
- :else
|
|
|
|
- (str before end))
|
|
|
|
- (subs value start-pos end-pos)))))
|
|
|
|
-
|
|
|
|
-(defn wrapped-by?
|
|
|
|
- "`pos` must be wrapped by `before` and `and` in string `value`, e.g. ((a|b))"
|
|
|
|
- [value pos before end]
|
|
|
|
- (let [before-matches (->> (get-string-all-indexes value before)
|
|
|
|
- (map (fn [i] [i :before])))
|
|
|
|
- end-matches (->> (get-string-all-indexes value end)
|
|
|
|
- (map (fn [i] [i :end])))
|
|
|
|
- indexes (sort-by first (concat before-matches end-matches [[pos :between]]))
|
|
|
|
- ks (map second indexes)
|
|
|
|
- q [:before :between :end]]
|
|
|
|
- (true?
|
|
|
|
- (reduce (fn [acc k]
|
|
|
|
- (if (= q (conj acc k))
|
|
|
|
- (reduced true)
|
|
|
|
- (vec (take-last 2 (conj acc k)))))
|
|
|
|
- []
|
|
|
|
- ks))))
|
|
|
|
-
|
|
|
|
-(defn get-graph-name-from-path
|
|
|
|
- [path]
|
|
|
|
- (when (string? path)
|
|
|
|
- (let [parts (->> (string/split path #"/")
|
|
|
|
- (take-last 2))]
|
|
|
|
- (-> (if (not= (first parts) "0")
|
|
|
|
- (string/join "/" parts)
|
|
|
|
- (last parts))
|
|
|
|
- js/decodeURI))))
|
|
|
|
-
|
|
|
|
(defonce non-parsing-properties
|
|
(defonce non-parsing-properties
|
|
(atom #{"background-color" "background_color"}))
|
|
(atom #{"background-color" "background_color"}))
|
|
|
|
|