mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-05 15:50:24 +08:00
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package docxlib
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"io"
|
|
)
|
|
|
|
type ParagraphChild struct {
|
|
Link *Hyperlink `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hyperlink,omitempty"`
|
|
Run *Run `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r,omitempty"`
|
|
Properties *RunProperties `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main rPr,omitempty"`
|
|
}
|
|
|
|
type Paragraph struct {
|
|
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main p"`
|
|
Data []ParagraphChild
|
|
|
|
file *DocxLib
|
|
}
|
|
|
|
func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
|
children := make([]ParagraphChild, 0)
|
|
for {
|
|
t, err := d.Token()
|
|
if err == io.EOF {
|
|
break
|
|
}
|
|
switch tt := t.(type) {
|
|
case xml.StartElement:
|
|
var elem ParagraphChild
|
|
if tt.Name.Local == "hyperlink" {
|
|
var value Hyperlink
|
|
d.DecodeElement(&value, &start)
|
|
elem = ParagraphChild{Link: &value}
|
|
} else if tt.Name.Local == "r" {
|
|
var value Run
|
|
d.DecodeElement(&value, &start)
|
|
elem = ParagraphChild{Run: &value}
|
|
} else if tt.Name.Local == "rPr" {
|
|
var value RunProperties
|
|
d.DecodeElement(&value, &start)
|
|
elem = ParagraphChild{Properties: &value}
|
|
} else {
|
|
continue
|
|
}
|
|
children = append(children, elem)
|
|
}
|
|
|
|
}
|
|
*p = Paragraph{Data: children}
|
|
return nil
|
|
|
|
}
|