mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-10 10:23:19 +08:00
First commit
This commit is contained in:
42
paragraph.go
Normal file
42
paragraph.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user