1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-09 17:50:27 +08:00

fix: recursive paragraph unmarshalling

This commit is contained in:
源文雨
2023-02-15 17:23:01 +08:00
parent 2771d05a51
commit 517198ded4
4 changed files with 85 additions and 8 deletions

View File

@@ -33,6 +33,8 @@ type Document struct {
XMLWP string `xml:"xmlns:wp,attr,omitempty"` // cannot be unmarshalled in
XMLWP14 string `xml:"xmlns:wp14,attr,omitempty"` // cannot be unmarshalled in
Body *Body
file *Docx
}
func (doc *Document) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
@@ -50,11 +52,16 @@ func (doc *Document) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error
switch tt := t.(type) {
case xml.StartElement:
switch tt.Name.Local {
case "body":
case "p":
var value Paragraph
d.DecodeElement(&value, &start)
doc.Body.Paragraphs = append(doc.Body.Paragraphs, &value)
if len(value.Children) > 0 {
value.file = doc.file
doc.Body.Paragraphs = append(doc.Body.Paragraphs, &value)
}
default:
d.Skip()
continue
}
}