🎨 Improve tag escaping

This commit is contained in:
Daniel 2025-04-23 22:17:06 +08:00
parent fc58892ce8
commit 618269e7df
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 11 additions and 0 deletions

View file

@ -112,9 +112,15 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str
re += ")"
ret = util.EscapeHTML(text)
ret = strings.ReplaceAll(ret, """, "\ue000")
ret = strings.ReplaceAll(ret, "<", "\ue001")
ret = strings.ReplaceAll(ret, ">", "\ue002")
if reg, err := regexp.Compile(re); err == nil {
ret = reg.ReplaceAllStringFunc(ret, func(s string) string { return openMark + s + closeMark })
}
ret = strings.ReplaceAll(ret, "\ue000", """)
ret = strings.ReplaceAll(ret, "\ue001", "<")
ret = strings.ReplaceAll(ret, "\ue002", ">")
// 搜索结果预览包含转义符问题 Search results preview contains escape character issue https://github.com/siyuan-note/siyuan/issues/9790
ret = strings.ReplaceAll(ret, "\\<span", "\\\\<span")