Skip to content

Commit

Permalink
🎨 Improve database exporting for asset field #12484
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 15, 2024
1 parent 7e19a77 commit 53d5423
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2339,6 +2339,20 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
if nil != cell.Value.Updated {
cell.Value.Updated = av.NewFormattedValueUpdated(cell.Value.Updated.Content, 0, av.UpdatedFormatNone)
}
} else if av.KeyTypeURL == cell.Value.Type {
if nil != cell.Value.URL {
if "" != strings.TrimSpace(cell.Value.URL.Content) {
link := &ast.Node{Type: ast.NodeLink}
link.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
link.AppendChild(&ast.Node{Type: ast.NodeLinkText, Tokens: []byte(cell.Value.URL.Content)})
link.AppendChild(&ast.Node{Type: ast.NodeCloseBracket})
link.AppendChild(&ast.Node{Type: ast.NodeOpenParen})
link.AppendChild(&ast.Node{Type: ast.NodeLinkDest, Tokens: []byte(cell.Value.URL.Content)})
link.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
mdTableCell.AppendChild(link)
}
continue
}
} else if av.KeyTypeMAsset == cell.Value.Type {
if nil != cell.Value.MAsset {
for i, a := range cell.Value.MAsset {
Expand All @@ -2353,18 +2367,23 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
img.AppendChild(&ast.Node{Type: ast.NodeCloseParen})
mdTableCell.AppendChild(img)
} else if av.AssetTypeFile == a.Type {
file := &ast.Node{Type: ast.NodeLink}
file.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
linkText := strings.TrimSpace(a.Name)
if "" == linkText {
linkText = a.Content
}
file.AppendChild(&ast.Node{Type: ast.NodeLinkText, Tokens: []byte(linkText)})
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)

if "" != strings.TrimSpace(a.Content) {
file := &ast.Node{Type: ast.NodeLink}
file.AppendChild(&ast.Node{Type: ast.NodeOpenBracket})
file.AppendChild(&ast.Node{Type: ast.NodeLinkText, Tokens: []byte(linkText)})
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)
} else {
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(linkText)})
}
}
if i < len(cell.Value.MAsset)-1 {
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(" ")})
Expand Down

0 comments on commit 53d5423

Please sign in to comment.