mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 Improve virtual reference split words https://github.com/siyuan-note/siyuan/issues/7833
This commit is contained in:
parent
8545454f74
commit
ed3fe917e5
1 changed files with 12 additions and 1 deletions
|
|
@ -18,10 +18,12 @@ package search
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/88250/gulu"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/88250/lute/lex"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -86,8 +88,17 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str
|
||||||
}
|
}
|
||||||
re := ic + "("
|
re := ic + "("
|
||||||
for i, k := range keywords {
|
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)
|
k = regexp.QuoteMeta(k)
|
||||||
re += "(" + k + ")"
|
re += "("
|
||||||
|
if wordBoundary {
|
||||||
|
re += "\\b"
|
||||||
|
}
|
||||||
|
re += k
|
||||||
|
if wordBoundary {
|
||||||
|
re += "\\b"
|
||||||
|
}
|
||||||
|
re += ")"
|
||||||
if i < len(keywords)-1 {
|
if i < len(keywords)-1 {
|
||||||
re += "|"
|
re += "|"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue