mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Improve highlighting of numbers and letters in global search preview Fix https://github.com/siyuan-note/siyuan/issues/8100
This commit is contained in:
parent
2494412f77
commit
a5be0036e9
3 changed files with 10 additions and 7 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue