🎨 Improve highlighting of numbers and letters in global search preview Fix https://github.com/siyuan-note/siyuan/issues/8100

This commit is contained in:
Liang Ding 2023-04-25 11:16:48 +08:00
parent 2494412f77
commit a5be0036e9
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 10 additions and 7 deletions

View file

@ -33,7 +33,7 @@ func MarkText(text string, keyword string, beforeLen int, caseSensitive bool) (p
}
text = util.EscapeHTML(text)
keywords := SplitKeyword(keyword)
marked = EncloseHighlighting(text, keywords, "<mark>", "</mark>", caseSensitive)
marked = EncloseHighlighting(text, keywords, "<mark>", "</mark>", caseSensitive, false)
pos = strings.Index(marked, "<mark>")
if 0 > pos {
@ -81,14 +81,17 @@ func SplitKeyword(keyword string) (keywords []string) {
return
}
func EncloseHighlighting(text string, keywords []string, openMark, closeMark string, caseSensitive bool) (ret string) {
func EncloseHighlighting(text string, keywords []string, openMark, closeMark string, caseSensitive, splitWords bool) (ret string) {
ic := "(?i)"
if caseSensitive {
ic = "(?)"
}
re := ic + "("
for i, k := range keywords {
wordBoundary := lex.IsASCIILetterNums(gulu.Str.ToBytes(k)) // Improve virtual reference split words https://github.com/siyuan-note/siyuan/issues/7833
wordBoundary := false
if splitWords {
wordBoundary = lex.IsASCIILetterNums(gulu.Str.ToBytes(k)) // Improve virtual reference split words https://github.com/siyuan-note/siyuan/issues/7833
}
k = regexp.QuoteMeta(k)
re += "("
if wordBoundary {