fix: escape regex for search

This commit is contained in:
Yukun Guo
2020-11-29 15:37:17 +08:00
committed by Tienson Qin
parent 5edd1a8ab0
commit 28cb5cd86c
3 changed files with 22 additions and 10 deletions

View File

@@ -26,10 +26,12 @@
(rum/defc highlight
[content q]
(let [q (search/clean q)
(let [q-pattern (->> q
(search/escape-str)
(str "(?i)")
(re-pattern))
n (count content)
[before after] (string/split content (re-find (re-pattern (str "(?i)" q))
content))
[before after] (string/split content q-pattern 2)
[before after] (if (>= n 64)
[(if before (apply str (take-last 48 before)))
(if after (apply str (take 48 after)))]