Browse Source

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

Liang Ding 2 years ago
parent
commit
fd2f3c4328
1 changed files with 17 additions and 0 deletions
  1. 17 0
      kernel/model/box.go

+ 17 - 0
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, " ")