Skip to content

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

:bug: 无法替换包含 HTML 转义的代码内容 https://github.com/siyuan-note/siyuan/issues/6476

Liang Dingf0088ccf8670
diff --git a/kernel/model/search.go b/kernel/model/search.go
index 5994fa6067..6b2ec11af5 100644
--- a/kernel/model/search.go
+++ b/kernel/model/search.go
@@ -207,6 +207,17 @@ func FindReplace(keyword, replacement string, ids []string) (err error) {
n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement))
}
case ast.NodeTextMark:
+ if n.IsTextMarkType("code") {
+ escapedKey := html.EscapeString(keyword)
+ if strings.Contains(n.TextMarkTextContent, escapedKey) {
+ n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, escapedKey, replacement)
+ }
+ } else {
+ if bytes.Contains(n.Tokens, []byte(keyword)) {
+ n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
+ }
+ }
+
if strings.Contains(n.TextMarkTextContent, keyword) {
n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement)
}