🎨 Improve database template field exporting Fix https://github.com/siyuan-note/siyuan/issues/11988
This commit is contained in:
parent
1a34e49edf
commit
a18559e6d0
2 changed files with 51 additions and 8 deletions
|
@ -110,6 +110,15 @@ func (row *TableRow) GetValue(keyID string) (ret *Value) {
|
|||
return
|
||||
}
|
||||
|
||||
func (table *Table) GetColumn(id string) *TableColumn {
|
||||
for _, column := range table.Columns {
|
||||
if column.ID == id {
|
||||
return column
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (table *Table) GetType() LayoutType {
|
||||
return LayoutTypeTable
|
||||
}
|
||||
|
|
|
@ -2246,10 +2246,16 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold bool,
|
|||
val = string(lex.EscapeProtyleMarkers([]byte(val)))
|
||||
val = strings.ReplaceAll(val, "\\|", "|")
|
||||
val = strings.ReplaceAll(val, "|", "\\|")
|
||||
lines := strings.Split(val, "\n")
|
||||
for _, line := range lines {
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(line)})
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeHardBreak})
|
||||
col := table.GetColumn(cell.Value.KeyID)
|
||||
if nil != col && col.Wrap {
|
||||
lines := strings.Split(val, "\n")
|
||||
for _, line := range lines {
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(line)})
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeHardBreak})
|
||||
}
|
||||
} else {
|
||||
val = strings.ReplaceAll(val, "\n", " ")
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(val)})
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
@ -2259,10 +2265,38 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold bool,
|
|||
val = string(lex.EscapeProtyleMarkers([]byte(val)))
|
||||
val = strings.ReplaceAll(val, "\\|", "|")
|
||||
val = strings.ReplaceAll(val, "|", "\\|")
|
||||
lines := strings.Split(val, "\n")
|
||||
for _, line := range lines {
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(line)})
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeHardBreak})
|
||||
col := table.GetColumn(cell.Value.KeyID)
|
||||
if nil != col && col.Wrap {
|
||||
lines := strings.Split(val, "\n")
|
||||
for _, line := range lines {
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(line)})
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeHardBreak})
|
||||
}
|
||||
} else {
|
||||
val = strings.ReplaceAll(val, "\n", " ")
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(val)})
|
||||
}
|
||||
continue
|
||||
}
|
||||
} else if av.KeyTypeTemplate == cell.Value.Type {
|
||||
if nil != cell.Value.Template {
|
||||
val = cell.Value.Template.Content
|
||||
if "<no value>" == val {
|
||||
val = ""
|
||||
}
|
||||
|
||||
val = strings.ReplaceAll(val, "\\|", "|")
|
||||
val = strings.ReplaceAll(val, "|", "\\|")
|
||||
col := table.GetColumn(cell.Value.KeyID)
|
||||
if nil != col && col.Wrap {
|
||||
lines := strings.Split(val, "\n")
|
||||
for _, line := range lines {
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(line)})
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeHardBreak})
|
||||
}
|
||||
} else {
|
||||
val = strings.ReplaceAll(val, "\n", " ")
|
||||
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(val)})
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue