🎨 Improve HTML content rendering for database template fields https://github.com/siyuan-note/siyuan/issues/16362

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-11-17 10:28:06 +08:00
parent 8cfae95f29
commit a3bb6cf4a6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -101,6 +101,25 @@ func UnescapeHTML(s string) (ret string) {
}
func HasUnclosedHtmlTag(htmlStr string) bool {
// 检查未闭合注释
openIdx := 0
for {
start := strings.Index(htmlStr[openIdx:], "<!--")
if start == -1 {
break
}
start += openIdx
end := strings.Index(htmlStr[start+4:], "-->")
if end == -1 {
return true // 存在未闭合注释
}
openIdx = start + 4 + end + 3
}
// 去除所有注释内容
commentRe := regexp.MustCompile(`<!--[\s\S]*?-->`)
htmlStr = commentRe.ReplaceAllString(htmlStr, "")
tagRe := regexp.MustCompile(`<(/?)([a-zA-Z0-9]+)[^>]*?>`)
selfClosing := map[string]bool{
"br": true, "img": true, "hr": true, "input": true, "meta": true, "link": true,