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

This commit is contained in:
Daniel 2023-12-05 22:47:57 +08:00
parent 16fa8a4548
commit 0b723479f1
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 9 additions and 5 deletions

View file

@ -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

View file

@ -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=

View file

@ -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)