🎨 Shallow clone the corresponding database when the template contains database blocks https://github.com/siyuan-note/siyuan/issues/9494
This commit is contained in:
parent
4796883707
commit
3bf01a7d9f
2 changed files with 36 additions and 10 deletions
|
@ -1890,16 +1890,10 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
|
|||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
var view *av.View
|
||||
if "" != attrView.ViewID {
|
||||
for _, v := range attrView.Views {
|
||||
if v.ID == attrView.ViewID {
|
||||
view = v
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view = attrView.Views[0]
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
logging.LogErrorf("get attribute view [%s] failed: %s", avID, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
table, err := renderAttributeViewTable(attrView, view)
|
||||
|
|
|
@ -290,9 +290,41 @@ func renderTemplate(p, id string, preview bool) (string, error) {
|
|||
if nil != cloned {
|
||||
n.AttributeViewID = cloned.ID
|
||||
if !preview {
|
||||
// 非预览时持久化数据库
|
||||
if saveErr := av.SaveAttributeView(cloned); nil != saveErr {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", cloned.ID, saveErr)
|
||||
}
|
||||
} else {
|
||||
// 预览时使用简单表格渲染
|
||||
view, getErr := attrView.GetView()
|
||||
if nil != getErr {
|
||||
logging.LogErrorf("get attribute view [%s] failed: %s", n.AttributeViewID, getErr)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
table, renderErr := renderAttributeViewTable(attrView, view)
|
||||
if nil != renderErr {
|
||||
logging.LogErrorf("render attribute view [%s] table failed: %s", n.AttributeViewID, renderErr)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
var aligns []int
|
||||
for range table.Columns {
|
||||
aligns = append(aligns, 0)
|
||||
}
|
||||
mdTable := &ast.Node{Type: ast.NodeTable, TableAligns: aligns}
|
||||
mdTableHead := &ast.Node{Type: ast.NodeTableHead}
|
||||
mdTable.AppendChild(mdTableHead)
|
||||
mdTableHeadRow := &ast.Node{Type: ast.NodeTableRow, TableAligns: aligns}
|
||||
mdTableHead.AppendChild(mdTableHeadRow)
|
||||
for _, col := range table.Columns {
|
||||
cell := &ast.Node{Type: ast.NodeTableCell}
|
||||
cell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(col.Name)})
|
||||
mdTableHeadRow.AppendChild(cell)
|
||||
}
|
||||
|
||||
n.InsertBefore(mdTable)
|
||||
unlinks = append(unlinks, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue