Skip to content

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

:art: 改进导入 Markdown 文件时解析 HTML 块 Fix https://github.com/siyuan-note/siyuan/issues/7137

Liang Dingfd2f3c432898
diff --git a/kernel/model/box.go b/kernel/model/box.go
index ce1cbc1314..121fd4f3e8 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -467,6 +467,23 @@ func genTreeID(tree *parse.Tree) {
n.ID = n.IALAttr("id")
}
+ if ast.NodeHTMLBlock == n.Type {
+ tokens := bytes.TrimSpace(n.Tokens)
+ if !bytes.HasPrefix(tokens, []byte("<div>")) {
+ tokens = []byte("<div>\n" + string(tokens))
+ }
+ if !bytes.HasSuffix(tokens, []byte("</div>")) {
+ tokens = append(tokens, []byte("\n</div>")...)
+ }
+ n.Tokens = tokens
+ return ast.WalkContinue
+ }
+
+ if ast.NodeInlineHTML == n.Type {
+ n.Type = ast.NodeText
+ return ast.WalkContinue
+ }
+
if ast.NodeParagraph == n.Type && nil != n.FirstChild && ast.NodeTaskListItemMarker == n.FirstChild.Type {
// 踢掉任务列表的第一个子节点左侧空格
n.FirstChild.Next.Tokens = bytes.TrimLeft(n.FirstChild.Next.Tokens, " ")