Skip to content

Commit

Permalink
Add tables loop to Paragraphs funcs of Header and Footer (unido…
Browse files Browse the repository at this point in the history
…c#303)

* Add `Tables` func for `Header`, `Footer`
* Embed tables loop into `Header.Paragraphs`, `Footer.Paragraphs`
  • Loading branch information
nkryuchkov authored and gunnsth committed Jun 24, 2019
1 parent f61dcc3 commit a3c3e9b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
46 changes: 46 additions & 0 deletions document/footer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ func (f Footer) Index() int {
return -1
}

// Tables returns the tables defined in the footer.
func (f Footer) Tables() []Table {
ret := []Table{}
if f.x == nil {
return nil
}
for _, c := range f.x.EG_ContentBlockContent {
for _, t := range f.tables(f.d, c) {
ret = append(ret, t)
}
}
return ret
}

// Paragraphs returns the paragraphs defined in a footer.
func (f Footer) Paragraphs() []Paragraph {
ret := []Paragraph{}
Expand All @@ -56,6 +70,14 @@ func (f Footer) Paragraphs() []Paragraph {
ret = append(ret, Paragraph{f.d, p})
}
}

for _, t := range f.Tables() {
for _, r := range t.Rows() {
for _, c := range r.Cells() {
ret = append(ret, c.Paragraphs()...)
}
}
}
return ret
}

Expand Down Expand Up @@ -106,3 +128,27 @@ func (f Footer) AddImage(i common.Image) (common.ImageRef, error) {
r.SetRelID(rel.X().IdAttr)
return r, nil
}

func (f Footer) tables(d *Document, bc *wml.EG_ContentBlockContent) []Table {
ret := []Table{}
for _, t := range bc.Tbl {
ret = append(ret, Table{d, t})
for _, crc := range t.EG_ContentRowContent {
for _, tr := range crc.Tr {
for _, ccc := range tr.EG_ContentCellContent {
for _, tc := range ccc.Tc {
for _, ble := range tc.EG_BlockLevelElts {
for _, cbc := range ble.EG_ContentBlockContent {
for _, tbl := range f.tables(d, cbc) {
ret = append(ret, tbl)
}
}
}
}
}
}
}
}

return ret
}
46 changes: 46 additions & 0 deletions document/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ func (h Header) Index() int {
return -1
}

// Tables returns the tables defined in the header.
func (h Header) Tables() []Table {
ret := []Table{}
if h.x == nil {
return nil
}
for _, c := range h.x.EG_ContentBlockContent {
for _, t := range h.tables(h.d, c) {
ret = append(ret, t)
}
}
return ret
}

// Paragraphs returns the paragraphs defined in a header.
func (h Header) Paragraphs() []Paragraph {
ret := []Paragraph{}
Expand All @@ -56,6 +70,14 @@ func (h Header) Paragraphs() []Paragraph {
ret = append(ret, Paragraph{h.d, p})
}
}

for _, t := range h.Tables() {
for _, r := range t.Rows() {
for _, c := range r.Cells() {
ret = append(ret, c.Paragraphs()...)
}
}
}
return ret
}

Expand Down Expand Up @@ -106,3 +128,27 @@ func (h Header) AddImage(i common.Image) (common.ImageRef, error) {
r.SetRelID(rel.X().IdAttr)
return r, nil
}

func (h Header) tables(d *Document, bc *wml.EG_ContentBlockContent) []Table {
ret := []Table{}
for _, t := range bc.Tbl {
ret = append(ret, Table{d, t})
for _, crc := range t.EG_ContentRowContent {
for _, tr := range crc.Tr {
for _, ccc := range tr.EG_ContentCellContent {
for _, tc := range ccc.Tc {
for _, ble := range tc.EG_BlockLevelElts {
for _, cbc := range ble.EG_ContentBlockContent {
for _, tbl := range h.tables(d, cbc) {
ret = append(ret, tbl)
}
}
}
}
}
}
}
}

return ret
}

0 comments on commit a3c3e9b

Please sign in to comment.