1
0
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:
Gonzalo Fernandez-Victorio
2021-05-12 21:27:28 +01:00
parent 965e28ba05
commit 4c88ae23fe
4 changed files with 47 additions and 26 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -95,6 +95,7 @@ func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
}
*r = elem
return nil
}