Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Sep 6, 2023
2 parents c33fef2 + 4dd8ec6 commit cad51d7
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
27 changes: 27 additions & 0 deletions kernel/av/av.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ type Value struct {
Phone *ValuePhone `json:"phone,omitempty"`
}

func (value *Value) String() string {
switch value.Type {
case KeyTypeBlock:
return value.Block.Content
case KeyTypeText:
return value.Text.Content
case KeyTypeNumber:
return value.Number.FormattedContent
case KeyTypeDate:
return value.Date.FormattedContent
case KeyTypeMSelect:
var ret []string
for _, v := range value.MSelect {
ret = append(ret, v.Content)
}
return strings.Join(ret, " ")
case KeyTypeURL:
return value.URL.Content
case KeyTypeEmail:
return value.Email.Content
case KeyTypePhone:
return value.Phone.Content
default:
return ""
}
}

func (value *Value) ToJSONString() string {
data, err := gulu.JSON.MarshalJSON(value)
if nil != err {
Expand Down
81 changes: 81 additions & 0 deletions kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/httpclient"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
Expand Down Expand Up @@ -1786,6 +1787,86 @@ func exportTree(tree *parse.Tree, wysiwyg, expandKaTexMacros, keepFold bool,
for _, emptyParagraph := range emptyParagraphs {
emptyParagraph.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(editor.Zwj)})
}

unlinks = nil
// Attribute View export https://github.com/siyuan-note/siyuan/issues/8710
ast.Walk(ret.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering {
return ast.WalkContinue
}

if ast.NodeAttributeView != n.Type {
return ast.WalkContinue
}

avID := n.AttributeViewID
if avJSONPath := av.GetAttributeViewDataPath(avID); !gulu.File.IsExist(avJSONPath) {
return ast.WalkContinue
}

attrView, err := av.ParseAttributeView(avID)
if nil != err {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return ast.WalkContinue
}

var view *av.View
if "" != attrView.ViewID {
for _, v := range attrView.Views {
if v.ID == attrView.ViewID {
view = v
break
}
}
} else {
view = attrView.Views[0]
}

table, err := renderAttributeViewTable(attrView, view)
if nil != err {
logging.LogErrorf("render attribute view [%s] table failed: %s", avID, err)
return ast.WalkContinue
}

var aligns []int
for range table.Columns {
aligns = append(aligns, 0)
}
mdTable := &ast.Node{Type: ast.NodeTable, TableAligns: aligns}
mdTableHead := &ast.Node{Type: ast.NodeTableHead}
mdTable.AppendChild(mdTableHead)
mdTableHeadRow := &ast.Node{Type: ast.NodeTableRow, TableAligns: aligns}
mdTableHead.AppendChild(mdTableHeadRow)
for _, col := range table.Columns {
cell := &ast.Node{Type: ast.NodeTableCell}
cell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(col.Name)})
mdTableHeadRow.AppendChild(cell)
}
for _, row := range table.Rows {
mdTableRow := &ast.Node{Type: ast.NodeTableRow, TableAligns: aligns}
mdTable.AppendChild(mdTableRow)
for _, cell := range row.Cells {
mdTableCell := &ast.Node{Type: ast.NodeTableCell}
mdTableRow.AppendChild(mdTableCell)
var val string
if nil != cell.Value {
if av.KeyTypeDate == cell.Value.Type && nil != cell.Value.Date {
cell.Value.Date = av.NewFormattedValueDate(cell.Value.Date.Content, cell.Value.Date.Content2, av.DateFormatNone)
}

val = cell.Value.String()
}
mdTableCell.AppendChild(&ast.Node{Type: ast.NodeText, Tokens: []byte(val)})
}
}

n.InsertBefore(mdTable)
unlinks = append(unlinks, n)
return ast.WalkContinue
})
for _, n := range unlinks {
n.Unlink()
}
return ret
}

Expand Down

0 comments on commit cad51d7

Please sign in to comment.