🎨 Creating a dailynote template supports doc attributes https://github.com/siyuan-note/siyuan/issues/10698

This commit is contained in:
Daniel 2024-03-22 20:36:18 +08:00
parent 852ca6744a
commit 8be272bfc6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -169,6 +169,16 @@ func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
luteEngine := NewLute()
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
md := formatRenderer.Render()
// 单独渲染根节点的 IAL
if 0 < len(tree.Root.KramdownIAL) {
// 把 docIAL 中的 id 调整到第一个
tree.Root.RemoveIALAttr("id")
tree.Root.KramdownIAL = append([][]string{{"id", tree.Root.ID}}, tree.Root.KramdownIAL...)
md = append(md, []byte("\n")...)
md = append(md, parse.IAL2Tokens(tree.Root.KramdownIAL)...)
}
name = util.FilterFileName(name) + ".md"
name = util.TruncateLenFileName(name)
savePath := filepath.Join(util.DataDir, "templates", name)