mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 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>
This commit is contained in:
parent
4de0be0bc1
commit
3a58d6dc60
1 changed files with 15 additions and 0 deletions
|
|
@ -650,6 +650,21 @@ func normalizeTree(tree *parse.Tree) (yfmRootID, yfmTitle, yfmUpdated string) {
|
||||||
|
|
||||||
tree.Root.SetIALAttr("custom-"+attrK, fmt.Sprint(attrV))
|
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 {
|
if ast.NodeYamlFrontMatter == n.Type {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue