🎨 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 8545454f74
commit ed3fe917e5
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

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 += "|"
}