mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-07 00:30:25 +08:00
More tests
This commit is contained in:
@@ -34,7 +34,7 @@ func main() {
|
||||
for _, para := range doc.Paragraphs() {
|
||||
glog.Infoln("There is a new paragraph", para)
|
||||
for _, child := range para.Children() {
|
||||
if child.Run != nil {
|
||||
if child.Run != nil && child.Run.Text != nil {
|
||||
fmt.Printf("\tWe've found a new run with the text ->%s\n", child.Run.Text.Text)
|
||||
}
|
||||
if child.Link != nil {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -3,6 +3,8 @@ package docxlib
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
type ParagraphChild struct {
|
||||
@@ -31,12 +33,23 @@ func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
if tt.Name.Local == "hyperlink" {
|
||||
var value Hyperlink
|
||||
d.DecodeElement(&value, &start)
|
||||
value.ID = getAtt(tt.Attr, "id")
|
||||
id := getAtt(tt.Attr, "id")
|
||||
anchor := getAtt(tt.Attr, "anchor")
|
||||
if id != "" {
|
||||
value.ID = id
|
||||
}
|
||||
if anchor != "" {
|
||||
value.ID = anchor
|
||||
}
|
||||
elem = ParagraphChild{Link: &value}
|
||||
} else if tt.Name.Local == "r" {
|
||||
var value Run
|
||||
d.DecodeElement(&value, &start)
|
||||
elem = ParagraphChild{Run: &value}
|
||||
if value.InstrText == "" && value.Text == nil {
|
||||
glog.V(0).Infof("Empty run, we ignore")
|
||||
continue
|
||||
}
|
||||
} else if tt.Name.Local == "rPr" {
|
||||
var value RunProperties
|
||||
d.DecodeElement(&value, &start)
|
||||
|
||||
@@ -95,6 +95,7 @@ func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
|
||||
}
|
||||
*r = elem
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user