-
Notifications
You must be signed in to change notification settings - Fork 0
/
htmltable.go
60 lines (55 loc) · 1.4 KB
/
htmltable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package htmlbag
import (
"github.com/boxesandglue/boxesandglue/backend/bag"
"github.com/boxesandglue/boxesandglue/backend/node"
"github.com/boxesandglue/boxesandglue/frontend"
)
func (cb *CSSBuilder) buildTable(te *frontend.Text, wd bag.ScaledPoint) (*node.VList, error) {
tbl := &frontend.Table{}
tbl.MaxWidth = wd
for _, itm := range te.Items {
switch t := itm.(type) {
case *frontend.Text:
elt := t.Settings[frontend.SettingDebug].(string)
if elt == "tbody" {
cb.buildTBody(t, tbl)
}
}
}
vl, err := cb.frontend.BuildTable(tbl)
if err != nil {
return nil, err
}
return vl[0], nil
}
func (cb *CSSBuilder) buildTBody(te *frontend.Text, tbl *frontend.Table) {
for _, itm := range te.Items {
switch t := itm.(type) {
case *frontend.Text:
elt := t.Settings[frontend.SettingDebug].(string)
if elt == "tr" {
cb.buildTR(t, tbl)
}
}
}
}
func (cb *CSSBuilder) buildTR(te *frontend.Text, tbl *frontend.Table) {
tr := &frontend.TableRow{}
for _, itm := range te.Items {
switch t := itm.(type) {
case *frontend.Text:
elt := t.Settings[frontend.SettingDebug].(string)
if elt == "td" {
cb.buildTD(t, tr)
}
}
}
tbl.Rows = append(tbl.Rows, tr)
}
func (cb *CSSBuilder) buildTD(te *frontend.Text, row *frontend.TableRow) {
td := &frontend.TableCell{}
for _, itm := range te.Items {
td.Contents = append(td.Contents, itm)
}
row.Cells = append(row.Cells, td)
}