Skip to content

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

:art: 虚拟引用和反链提及关键字按最长匹配优先 Fix https://github.com/siyuan-note/siyuan/issues/7465

Liang Dingbc1ab2b52f61
diff --git a/kernel/model/search.go b/kernel/model/search.go
index 8288f0da3c..25b4fbf159 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -986,6 +986,9 @@ func markReplaceSpan(n *ast.Node, unlinks *[]*ast.Node, keywords []string, markS
// markReplaceSpanWithSplit 用于处理虚拟引用和反链提及高亮。
func markReplaceSpanWithSplit(text string, keywords []string, replacementStart, replacementEnd string) (ret string) {
+ // 虚拟引用和反链提及关键字按最长匹配优先 https://github.com/siyuan-note/siyuan/issues/7465
+ sort.Slice(keywords, func(i, j int) bool { return len(keywords[i]) > len(keywords[j]) })
+
tmp := search.EncloseHighlighting(text, keywords, replacementStart, replacementEnd, Conf.Search.CaseSensitive)
parts := strings.Split(tmp, replacementEnd)
buf := bytes.Buffer{}