🎨 Improve database asset field exporting https://github.com/siyuan-note/siyuan/issues/11903

This commit is contained in:
Daniel 2024-07-10 22:32:42 +08:00
parent 1e0eb6dc90
commit fd0c231b94
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -2243,26 +2243,29 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold bool,
}
} else if av.KeyTypeMAsset == cell.Value.Type {
if nil != cell.Value.MAsset {
buf := &bytes.Buffer{}
for _, a := range cell.Value.MAsset {
if av.AssetTypeImage == a.Type {
buf.WriteString("![")
buf.WriteString(a.Name)
buf.WriteString("](")
buf.WriteString(a.Content)
buf.WriteString(") ")
img := &ast.Node{Type: ast.NodeImage}
img.AppendChild(&ast.Node{Type: ast.NodeBang})
img.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
img.AppendChild(&ast.Node{Type: ast.NodeLinkText, Tokens: []byte(a.Name)})
img.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
img.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
img.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: []byte(a.Content)})
img.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
mdTableCell.AppendChild(img)
} else if av.AssetTypeFile == a.Type {
buf.WriteString("[")
buf.WriteString(a.Name)
buf.WriteString("](")
buf.WriteString(a.Content)
buf.WriteString(") ")
} else {
buf.WriteString(a.Content)
buf.WriteString(" ")
file := &ast.Node{Type: ast.NodeLink}
file.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
file.AppendChild(&ast.Node{Type: ast.NodeLinkText, Tokens: []byte(a.Name)})
file.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
file.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
file.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: []byte(a.Content)})
file.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
mdTableCell.AppendChild(file)
}
}
val = strings.TrimSpace(buf.String())
continue
}
} else if av.KeyTypeLineNumber == cell.Value.Type {
val = strconv.Itoa(rowNum)