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