瀏覽代碼

:art: Improve database exporting for asset field https://github.com/siyuan-note/siyuan/issues/12484

Daniel 10 月之前
父節點
當前提交
53d5423770
共有 1 個文件被更改,包括 27 次插入8 次删除
  1. 27 8
      kernel/model/export.go

+ 27 - 8
kernel/model/export.go

@@ -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 {
@@ -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(" ")})