🎨 Improve virtual reference split words https://github.com/siyuan-note/siyuan/issues/7833

This commit is contained in:
Liang Ding
2023-03-30 19:51:22 +08:00
parent fe0c7b90a3
commit 1f6d45b375

View File

@@ -18,10 +18,12 @@ package search
import (
"fmt"
"github.com/88250/gulu"
"regexp"
"strings"
"unicode/utf8"
"github.com/88250/lute/lex"
"github.com/siyuan-note/siyuan/kernel/util"
)
@@ -86,8 +88,17 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str
}
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
k = regexp.QuoteMeta(k)
re += "(" + k + ")"
re += "("
if wordBoundary {
re += "\\b"
}
re += k
if wordBoundary {
re += "\\b"
}
re += ")"
if i < len(keywords)-1 {
re += "|"
}