mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-13 04:13:15 +08:00
fix: Paragraph.MarshalXML
This commit is contained in:
@@ -59,6 +59,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
for _, para := range doc.Document.Body.Paragraphs {
|
for _, para := range doc.Document.Body.Paragraphs {
|
||||||
|
fmt.Println("New paragraph")
|
||||||
for _, child := range para.Children {
|
for _, child := range para.Children {
|
||||||
if child.Run != nil {
|
if child.Run != nil {
|
||||||
if child.Run.Text != nil {
|
if child.Run.Text != nil {
|
||||||
@@ -80,6 +81,7 @@ func main() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Print("End of paragraph\n\n")
|
||||||
}
|
}
|
||||||
fmt.Println("End of main")
|
fmt.Println("End of main")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -571,6 +571,8 @@ func TestMarshalDrawingStructure(t *testing.T) {
|
|||||||
|
|
||||||
para2 := w.AddParagraph()
|
para2 := w.AddParagraph()
|
||||||
para2.AddText("test font size and color").Size(22).Color("ff0000")
|
para2.AddText("test font size and color").Size(22).Color("ff0000")
|
||||||
|
para2.AddText("test font size and color").Size(22).Color("ff0000")
|
||||||
|
para2.AddText("test font size and color").Size(22).Color("ff0000")
|
||||||
|
|
||||||
nextPara := w.AddParagraph()
|
nextPara := w.AddParagraph()
|
||||||
nextPara.AddLink("google", `http://google.com`)
|
nextPara.AddLink("google", `http://google.com`)
|
||||||
|
|||||||
@@ -19,10 +19,26 @@ type Paragraph struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Paragraph) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
func (p *Paragraph) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||||
for _, c := range p.Children {
|
err := e.EncodeToken(start)
|
||||||
e.EncodeElement(c, start)
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
for _, c := range p.Children {
|
||||||
|
switch {
|
||||||
|
case c.Link != nil:
|
||||||
|
err = e.Encode(c.Link)
|
||||||
|
case c.Run != nil:
|
||||||
|
err = e.Encode(c.Run)
|
||||||
|
case c.Properties != nil:
|
||||||
|
err = e.Encode(c.Properties)
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return e.EncodeToken(start.End())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user