mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-06 16:20:24 +08:00
43 lines
875 B
Go
43 lines
875 B
Go
package docxlib
|
|
|
|
import (
|
|
"encoding/xml"
|
|
)
|
|
|
|
type ParagraphChild struct {
|
|
Link *Hyperlink `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main hyperlink"`
|
|
Run *Run `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main r"`
|
|
}
|
|
|
|
type Paragraph struct {
|
|
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main p"`
|
|
Data []ParagraphChild
|
|
|
|
file *Docx
|
|
}
|
|
|
|
// AddParagraph adds a new paragraph
|
|
func (f *Docx) AddParagraph() *Paragraph {
|
|
p := &Paragraph{
|
|
Data: make([]ParagraphChild, 0),
|
|
file: f,
|
|
}
|
|
|
|
f.Document.Body.Paragraphs = append(f.Document.Body.Paragraphs, p)
|
|
return p
|
|
}
|
|
|
|
func (f *Docx) Paragraphs() []*Paragraph {
|
|
return f.Document.Body.Paragraphs
|
|
}
|
|
|
|
func (p *Paragraph) Runs() (ret []*Run) {
|
|
data := p.Data
|
|
for _, d := range data {
|
|
if d.Run != nil {
|
|
ret = append(ret, d.Run)
|
|
}
|
|
}
|
|
return
|
|
}
|