🎨 Supports rendering the row number column when exporting database https://github.com/siyuan-note/siyuan/issues/11192
This commit is contained in:
parent
653ac93875
commit
de7a776b65
1 changed files with 47 additions and 10 deletions
|
@ -119,6 +119,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
rowNum := 1
|
||||
for _, row := range table.Rows {
|
||||
var rowVal []string
|
||||
for _, cell := range row.Cells {
|
||||
|
@ -140,15 +141,32 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
if nil != cell.Value.MAsset {
|
||||
buf := &bytes.Buffer{}
|
||||
for _, a := range cell.Value.MAsset {
|
||||
buf.WriteString("
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
if av.AssetTypeImage == a.Type {
|
||||
buf.WriteString("
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
} 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(" ")
|
||||
}
|
||||
}
|
||||
val = strings.TrimSpace(buf.String())
|
||||
}
|
||||
} else if av.KeyTypeLineNumber == cell.Value.Type {
|
||||
val = strconv.Itoa(rowNum)
|
||||
}
|
||||
|
||||
val = cell.Value.String(true)
|
||||
if "" == val {
|
||||
val = cell.Value.String(true)
|
||||
}
|
||||
}
|
||||
|
||||
rowVal = append(rowVal, val)
|
||||
|
@ -158,6 +176,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
f.Close()
|
||||
return
|
||||
}
|
||||
rowNum++
|
||||
}
|
||||
writer.Flush()
|
||||
|
||||
|
@ -2301,6 +2320,8 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
|
|||
cell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(col.Name)})
|
||||
mdTableHeadRow.AppendChild(cell)
|
||||
}
|
||||
|
||||
rowNum := 1
|
||||
for _, row := range table.Rows {
|
||||
mdTableRow := &ast.Node{Type: ast.NodeTableRow, TableAligns: aligns}
|
||||
mdTable.AppendChild(mdTableRow)
|
||||
|
@ -2325,17 +2346,33 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
|
|||
if nil != cell.Value.MAsset {
|
||||
buf := &bytes.Buffer{}
|
||||
for _, a := range cell.Value.MAsset {
|
||||
buf.WriteString("
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
if av.AssetTypeImage == a.Type {
|
||||
buf.WriteString("
|
||||
buf.WriteString(a.Content)
|
||||
buf.WriteString(") ")
|
||||
} 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(" ")
|
||||
}
|
||||
}
|
||||
val = strings.TrimSpace(buf.String())
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(val)})
|
||||
continue
|
||||
}
|
||||
} else if av.KeyTypeLineNumber == cell.Value.Type {
|
||||
val = strconv.Itoa(rowNum)
|
||||
rowNum++
|
||||
}
|
||||
|
||||
val = cell.Value.String(true)
|
||||
if "" == val {
|
||||
val = cell.Value.String(true)
|
||||
}
|
||||
}
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(val)})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue