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

This commit is contained in:
Liang Ding 2022-11-04 15:44:39 +08:00
parent 75925c9e4f
commit f0088ccf86
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D

View File

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