mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 Support focus block export template https://github.com/siyuan-note/siyuan/issues/8117
This commit is contained in:
parent
9cb6e9ec25
commit
1c47a63cca
4 changed files with 63 additions and 27 deletions
|
|
@ -132,21 +132,20 @@ func SearchTemplate(keyword string) (ret []*Block) {
|
|||
return
|
||||
}
|
||||
|
||||
func DocSaveAsTemplate(id string, overwrite bool) (code int, err error) {
|
||||
tree, err := loadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
return
|
||||
}
|
||||
|
||||
tree := prepareExportTree(bt)
|
||||
addBlockIALNodes(tree, true)
|
||||
|
||||
luteEngine := NewLute()
|
||||
formatRenderer := render.NewFormatRenderer(tree, luteEngine.RenderOptions)
|
||||
md := formatRenderer.Render()
|
||||
title := tree.Root.IALAttr("title")
|
||||
title = util.FilterFileName(title)
|
||||
title += ".md"
|
||||
savePath := filepath.Join(util.DataDir, "templates", title)
|
||||
name = util.FilterFileName(name) + ".md"
|
||||
savePath := filepath.Join(util.DataDir, "templates", name)
|
||||
if gulu.File.IsExist(savePath) {
|
||||
if !overwrite {
|
||||
code = 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue