Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve search preview to highlight text `<foo>` https://github.com/siyuan-note/siyuan/issues/9821

Daniel0b723479f137
diff --git a/kernel/go.mod b/kernel/go.mod
index 3d3c0fd4e9..ffbbc0530e 100644
--- a/kernel/go.mod
+++ b/kernel/go.mod
@@ -9,7 +9,7 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/gulu v1.2.3-0.20231205093500-bcc43ee27cba
- github.com/88250/lute v1.7.6-0.20231202134329-1e21d618bebc
+ github.com/88250/lute v1.7.6-0.20231205144411-36eb02d113a6
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
@@ -174,7 +174,8 @@ replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20
//replace github.com/siyuan-note/riff => D:\88250\riff
//replace github.com/siyuan-note/httpclient => D:\88250\httpclient
//replace github.com/siyuan-note/filelock => D:\88250\filelock
-//replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute
+replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute
+
//replace github.com/88250/pdfcpu => D:\88250\pdfcpu
//replace github.com/siyuan-note/filelock => D:\88250\filelock
//replace github.com/88250/gulu => D:\88250\gulu
diff --git a/kernel/go.sum b/kernel/go.sum
index 5334717144..532e9a6562 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -10,8 +10,6 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20231205093500-bcc43ee27cba h1:ypA1nYRPXm+oac3GnAziPOhMx49nTLtrajePha1CU0g=
github.com/88250/gulu v1.2.3-0.20231205093500-bcc43ee27cba/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
-github.com/88250/lute v1.7.6-0.20231202134329-1e21d618bebc h1:+ZB/qnOSevdt4beKpALW5d4sA6Zd+eado03Gbz04Os4=
-github.com/88250/lute v1.7.6-0.20231202134329-1e21d618bebc/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
diff --git a/kernel/model/search.go b/kernel/model/search.go
index f0a4d379ea..ae63ac5581 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -1102,7 +1102,12 @@ func stringQuery(query string) string {
func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markSpanDataType string, luteEngine *lute.Lute) bool {
text := n.Content()
if ast.NodeText == n.Type {
- text = search.EncloseHighlighting(text, keywords, search.GetMarkSpanStart(markSpanDataType), search.GetMarkSpanEnd(), Conf.Search.CaseSensitive, false)
+ text = util.EscapeHTML(text)
+ escapedKeywords := make([]string, len(keywords))
+ for i, keyword := range keywords {
+ escapedKeywords[i] = util.EscapeHTML(keyword)
+ }
+ text = search.EncloseHighlighting(text, escapedKeywords, search.GetMarkSpanStart(markSpanDataType), search.GetMarkSpanEnd(), Conf.Search.CaseSensitive, false)
n.Tokens = gulu.Str.ToBytes(text)
if bytes.Contains(n.Tokens, []byte(search.MarkDataType)) {
linkTree := parse.Inline("", n.Tokens, luteEngine.ParseOptions)