Skip to content

Commit

Permalink
🎨 Improve database template field exporting Fix #11988
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jul 16, 2024
1 parent 1a34e49 commit a18559e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
9 changes: 9 additions & 0 deletions kernel/av/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
50 changes: 42 additions & 8 deletions kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit a18559e

Please sign in to comment.