From 3a58d6dc60914baeab0612abb043b56690bc7739 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 2 Dec 2025 17:37:31 +0800 Subject: [PATCH] :art: Import the YAML at the beginning of the Markdown as a code block https://github.com/siyuan-note/siyuan/issues/16488 Signed-off-by: Daniel <845765@qq.com> --- kernel/model/box.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/kernel/model/box.go b/kernel/model/box.go index 0f4edfb8b..d6ca8147c 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -650,6 +650,21 @@ func normalizeTree(tree *parse.Tree) (yfmRootID, yfmTitle, yfmUpdated string) { tree.Root.SetIALAttr("custom-"+attrK, fmt.Sprint(attrV)) } + + // Import the YAML at the beginning of the Markdown as a code block https://github.com/siyuan-note/siyuan/issues/16488 + codeBlock := &ast.Node{Type: ast.NodeCodeBlock} + openMarker := &ast.Node{Type: ast.NodeCodeBlockFenceOpenMarker, Tokens: []byte("```"), CodeBlockFenceLen: 3} + codeBlock.AppendChild(openMarker) + info := &ast.Node{Type: ast.NodeCodeBlockFenceInfoMarker, CodeBlockInfo: []byte("yaml")} + codeBlock.AppendChild(info) + content := []byte("---\n") + content = append(content, n.Tokens...) + content = append(content, []byte("\n---")...) + code := &ast.Node{Type: ast.NodeCodeBlockCode, Tokens: content} + codeBlock.AppendChild(code) + closeMarker := &ast.Node{Type: ast.NodeCodeBlockFenceCloseMarker, Tokens: []byte("```"), CodeBlockFenceLen: 3} + codeBlock.AppendChild(closeMarker) + tree.Root.PrependChild(codeBlock) } if ast.NodeYamlFrontMatter == n.Type {