1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-12 19:58:36 +08:00

make lint happy

This commit is contained in:
源文雨
2023-02-23 15:22:56 +08:00
parent 958a125885
commit b9c9164250
14 changed files with 76 additions and 38 deletions

View File

@@ -15,9 +15,9 @@ func (p *Paragraph) AddInlineDrawing(pic []byte) (*Run, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
idn := int(atomic.AddUintptr(&p.file.imageId, 1)) idn := int(atomic.AddUintptr(&p.file.imageID, 1))
id := strconv.Itoa(idn) id := strconv.Itoa(idn)
rId := p.file.addImage(Media{Name: "image" + id + "." + format, Data: pic}) rid := p.file.addImage(Media{Name: "image" + id + "." + format, Data: pic})
w, h := int64(sz.Width), int64(sz.Height) w, h := int64(sz.Width), int64(sz.Height)
if float64(w)/float64(h) > 1.2 { if float64(w)/float64(h) > 1.2 {
h = A4_EMU_MAX_WIDTH * h / w h = A4_EMU_MAX_WIDTH * h / w
@@ -59,7 +59,7 @@ func (p *Paragraph) AddInlineDrawing(pic []byte) (*Run, error) {
}, },
BlipFill: &PICBlipFill{ BlipFill: &PICBlipFill{
Blip: ABlip{ Blip: ABlip{
Embed: rId, Embed: rid,
Cstate: "print", Cstate: "print",
}, },
}, },
@@ -114,7 +114,7 @@ func (p *Paragraph) AddAnchorDrawing(pic []byte) (*Run, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
idn := int(atomic.AddUintptr(&p.file.imageId, 1)) idn := int(atomic.AddUintptr(&p.file.imageID, 1))
id := strconv.Itoa(idn) id := strconv.Itoa(idn)
rId := p.file.addImage(Media{Name: "image" + id + "." + format, Data: pic}) rId := p.file.addImage(Media{Name: "image" + id + "." + format, Data: pic})
w, h := int64(sz.Width), int64(sz.Height) w, h := int64(sz.Width), int64(sz.Height)
@@ -195,7 +195,7 @@ func (p *Paragraph) AddAnchorDrawing(pic []byte) (*Run, error) {
return run, nil return run, nil
} }
// AddInlineDrawingFrom adds drawing from file to paragraph // AddAnchorDrawingFrom adds drawing from file to paragraph
func (p *Paragraph) AddAnchorDrawingFrom(file string) (*Run, error) { func (p *Paragraph) AddAnchorDrawingFrom(file string) (*Run, error) {
data, err := os.ReadFile(file) data, err := os.ReadFile(file)
if err != nil { if err != nil {

View File

@@ -12,14 +12,15 @@ import (
// Docx is the structure that allow to access the internal represntation // Docx is the structure that allow to access the internal represntation
// in memory of the doc (either read or about to be written) // in memory of the doc (either read or about to be written)
type Docx struct { type Docx struct {
Document Document Document Document // Document is word/document.xml
DocRelation Relationships
docRelation Relationships // docRelation is word/_rels/document.xml.rels
media []Media media []Media
mediaNameIdx map[string]int mediaNameIdx map[string]int
rId uintptr rID uintptr
imageId uintptr imageID uintptr
template string template string
tmplfs fs.FS tmplfs fs.FS

View File

@@ -19,7 +19,7 @@ func newEmptyA4File() *Docx {
Paragraphs: make([]Paragraph, 0, 64), Paragraphs: make([]Paragraph, 0, 64),
}, },
}, },
DocRelation: Relationships{ docRelation: Relationships{
Xmlns: XMLNS_REL, Xmlns: XMLNS_REL,
Relationship: []Relationship{ Relationship: []Relationship{
{ {
@@ -51,7 +51,7 @@ func newEmptyA4File() *Docx {
}, },
media: make([]Media, 0, 64), media: make([]Media, 0, 64),
mediaNameIdx: make(map[string]int, 64), mediaNameIdx: make(map[string]int, 64),
rId: 5, rID: 5,
template: "a4", template: "a4",
tmpfslst: []string{ tmpfslst: []string{
"_rels/.rels", "_rels/.rels",

3
fs.go
View File

@@ -3,7 +3,8 @@ package docxlib
import "embed" import "embed"
var ( var (
// TemplateXMLFS stores template docx files
//go:embed xml //go:embed xml
//go:embed xml/a4/_rels/* //go:embed xml/a4/_rels/*
TEMP_XML_FS embed.FS TemplateXMLFS embed.FS
) )

20
link.go
View File

@@ -18,13 +18,13 @@ var (
// this func is not thread-safe // this func is not thread-safe
func (f *Docx) addLinkRelation(link string) string { func (f *Docx) addLinkRelation(link string) string {
rel := Relationship{ rel := Relationship{
ID: "rId" + strconv.Itoa(int(atomic.AddUintptr(&f.rId, 1))), ID: "rId" + strconv.Itoa(int(atomic.AddUintptr(&f.rID, 1))),
Type: REL_HYPERLINK, Type: REL_HYPERLINK,
Target: link, Target: link,
TargetMode: REL_TARGETMODE, TargetMode: REL_TARGETMODE,
} }
f.DocRelation.Relationship = append(f.DocRelation.Relationship, rel) f.docRelation.Relationship = append(f.docRelation.Relationship, rel)
return rel.ID return rel.ID
} }
@@ -34,21 +34,21 @@ func (f *Docx) addLinkRelation(link string) string {
// this func is not thread-safe // this func is not thread-safe
func (f *Docx) addImageRelation(m Media) string { func (f *Docx) addImageRelation(m Media) string {
rel := Relationship{ rel := Relationship{
ID: "rId" + strconv.Itoa(int(atomic.AddUintptr(&f.rId, 1))), ID: "rId" + strconv.Itoa(int(atomic.AddUintptr(&f.rID, 1))),
Type: REL_IMAGE, Type: REL_IMAGE,
Target: "media/" + m.Name, Target: "media/" + m.Name,
} }
f.DocRelation.Relationship = append(f.DocRelation.Relationship, rel) f.docRelation.Relationship = append(f.docRelation.Relationship, rel)
return rel.ID return rel.ID
} }
// ReferTarget gets the target for a reference // ReferTarget gets the target for a reference
func (f *Docx) ReferTarget(id string) (string, error) { func (f *Docx) ReferTarget(id string) (string, error) {
f.DocRelation.mu.RLock() f.docRelation.mu.RLock()
defer f.DocRelation.mu.RUnlock() defer f.docRelation.mu.RUnlock()
for _, a := range f.DocRelation.Relationship { for _, a := range f.docRelation.Relationship {
if a.ID == id { if a.ID == id {
return a.Target, nil return a.Target, nil
} }
@@ -58,9 +58,9 @@ func (f *Docx) ReferTarget(id string) (string, error) {
// ReferID gets the rId from target // ReferID gets the rId from target
func (f *Docx) ReferID(target string) (string, error) { func (f *Docx) ReferID(target string) (string, error) {
f.DocRelation.mu.RLock() f.docRelation.mu.RLock()
defer f.DocRelation.mu.RUnlock() defer f.docRelation.mu.RUnlock()
for _, a := range f.DocRelation.Relationship { for _, a := range f.docRelation.Relationship {
if a.Target == target { if a.Target == target {
return a.ID, nil return a.ID, nil
} }

View File

@@ -8,7 +8,7 @@ import (
"os" "os"
) )
// This receives a zip file writer (word documents are a zip with multiple xml inside) // pack receives a zip file writer (word documents are a zip with multiple xml inside)
// and writes the relevant files. Some of them come from the empty_constants file, // and writes the relevant files. Some of them come from the empty_constants file,
// others from the actual in-memory structure // others from the actual in-memory structure
func (f *Docx) pack(zipWriter *zip.Writer) (err error) { func (f *Docx) pack(zipWriter *zip.Writer) (err error) {
@@ -16,7 +16,7 @@ func (f *Docx) pack(zipWriter *zip.Writer) (err error) {
if f.template != "" { if f.template != "" {
for _, name := range f.tmpfslst { for _, name := range f.tmpfslst {
files[name], err = TEMP_XML_FS.Open("xml/" + f.template + "/" + name) files[name], err = TemplateXMLFS.Open("xml/" + f.template + "/" + name)
if err != nil { if err != nil {
return return
} }
@@ -30,7 +30,7 @@ func (f *Docx) pack(zipWriter *zip.Writer) (err error) {
} }
} }
files["word/_rels/document.xml.rels"] = marshaller{data: &f.DocRelation} files["word/_rels/document.xml.rels"] = marshaller{data: &f.docRelation}
files["word/document.xml"] = marshaller{data: &f.Document} files["word/document.xml"] = marshaller{data: &f.Document}
for _, m := range f.media { for _, m := range f.media {

View File

@@ -25,6 +25,7 @@ func getAtt(atts []xml.Attr, name string) string {
return "" return ""
} }
// Body <w:body>
type Body struct { type Body struct {
mu sync.Mutex mu sync.Mutex
Paragraphs []Paragraph `xml:"w:p,omitempty"` Paragraphs []Paragraph `xml:"w:p,omitempty"`
@@ -32,6 +33,7 @@ type Body struct {
file *Docx file *Docx
} }
// UnmarshalXML ...
func (b *Body) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (b *Body) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -68,6 +70,7 @@ func (b *Body) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
} }
// Document <w:document>
type Document struct { type Document struct {
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main document"` XMLName xml.Name `xml:"http://schemas.openxmlformats.org/wordprocessingml/2006/main document"`
XMLW string `xml:"xmlns:w,attr"` // cannot be unmarshalled in XMLW string `xml:"xmlns:w,attr"` // cannot be unmarshalled in
@@ -78,6 +81,7 @@ type Document struct {
Body Body `xml:"w:body"` Body Body `xml:"w:body"`
} }
// UnmarshalXML ...
func (doc *Document) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (doc *Document) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()

View File

@@ -24,6 +24,7 @@ type Drawing struct {
Anchor *WPAnchor Anchor *WPAnchor
} }
// UnmarshalXML ...
func (r *Drawing) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *Drawing) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -75,6 +76,7 @@ type WPInline struct {
Graphic *AGraphic Graphic *AGraphic
} }
// UnmarshalXML ...
func (r *WPInline) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { func (r *WPInline) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
for _, attr := range start.Attr { for _, attr := range start.Attr {
switch attr.Name.Local { switch attr.Name.Local {
@@ -180,6 +182,7 @@ type WPExtent struct {
CY int64 `xml:"cy,attr"` CY int64 `xml:"cy,attr"`
} }
// UnmarshalXML ...
func (r *WPExtent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *WPExtent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var err error var err error
for _, attr := range start.Attr { for _, attr := range start.Attr {
@@ -213,6 +216,7 @@ type WPEffectExtent struct {
B int64 `xml:"b,attr"` B int64 `xml:"b,attr"`
} }
// UnmarshalXML ...
func (r *WPEffectExtent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *WPEffectExtent) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var err error var err error
for _, attr := range start.Attr { for _, attr := range start.Attr {
@@ -254,6 +258,7 @@ type WPDocPr struct {
Name string `xml:"name,attr,omitempty"` Name string `xml:"name,attr,omitempty"`
} }
// UnmarshalXML ...
func (r *WPDocPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *WPDocPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, attr := range start.Attr { for _, attr := range start.Attr {
switch attr.Name.Local { switch attr.Name.Local {
@@ -284,6 +289,7 @@ type WPCNvGraphicFramePr struct {
Locks *AGraphicFrameLocks Locks *AGraphicFrameLocks
} }
// UnmarshalXML ...
func (w *WPCNvGraphicFramePr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (w *WPCNvGraphicFramePr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -329,6 +335,7 @@ type AGraphic struct {
GraphicData *AGraphicData GraphicData *AGraphicData
} }
// UnmarshalXML ...
func (a *AGraphic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (a *AGraphic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, attr := range start.Attr { for _, attr := range start.Attr {
switch attr.Name.Local { switch attr.Name.Local {
@@ -373,6 +380,7 @@ type AGraphicData struct {
Pic *PICPic Pic *PICPic
} }
// UnmarshalXML ...
func (a *AGraphicData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (a *AGraphicData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -411,6 +419,7 @@ type PICPic struct {
SpPr *PICSpPr SpPr *PICSpPr
} }
// UnmarshalXML ...
func (p *PICPic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (p *PICPic) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -460,6 +469,7 @@ type PICNonVisualPicProperties struct {
CNvPicPr PicCNvPicPr CNvPicPr PicCNvPicPr
} }
// UnmarshalXML ...
func (p *PICNonVisualPicProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (p *PICNonVisualPicProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -495,6 +505,7 @@ type PicCNvPicPr struct {
Locks *APicLocks Locks *APicLocks
} }
// UnmarshalXML ...
func (p *PicCNvPicPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (p *PicCNvPicPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// Loop through XML tokens // Loop through XML tokens
for { for {
@@ -544,6 +555,7 @@ type PICBlipFill struct {
Stretch AStretch Stretch AStretch
} }
// UnmarshalXML ...
func (p *PICBlipFill) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (p *PICBlipFill) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -583,6 +595,7 @@ type ABlip struct {
AlphaModFix *AAlphaModFix AlphaModFix *AAlphaModFix
} }
// UnmarshalXML ...
func (a *ABlip) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (a *ABlip) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, attr := range start.Attr { for _, attr := range start.Attr {
switch attr.Name.Local { switch attr.Name.Local {
@@ -645,6 +658,7 @@ type PICSpPr struct {
PrstGeom APrstGeom PrstGeom APrstGeom
} }
// UnmarshalXML ...
func (p *PICSpPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (p *PICSpPr) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -688,6 +702,7 @@ type AXfrm struct {
Ext AExt Ext AExt
} }
// UnmarshalXML ...
func (a *AXfrm) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { func (a *AXfrm) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
for _, attr := range start.Attr { for _, attr := range start.Attr {
switch attr.Name.Local { switch attr.Name.Local {
@@ -779,6 +794,7 @@ type AAvLst struct {
RawXML string `xml:",innerxml"` RawXML string `xml:",innerxml"`
} }
// UnmarshalXML ...
func (a *AAvLst) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { func (a *AAvLst) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
var content []byte var content []byte
@@ -838,6 +854,7 @@ type WPAnchor struct {
Graphic *AGraphic Graphic *AGraphic
} }
// UnmarshalXML ...
func (r *WPAnchor) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { func (r *WPAnchor) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
for _, tt := range start.Attr { for _, tt := range start.Attr {
switch tt.Name.Local { switch tt.Name.Local {
@@ -985,11 +1002,12 @@ type WPPositionH struct {
PosOffset int64 `xml:"wp:posOffset"` PosOffset int64 `xml:"wp:posOffset"`
} }
// UnmarshalXML ...
func (r *WPPositionH) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *WPPositionH) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, attr := range start.Attr { for _, attr := range start.Attr {
switch attr.Name.Local { if attr.Name.Local == "relativeFrom" {
case "relativeFrom":
r.RelativeFrom = attr.Value r.RelativeFrom = attr.Value
break
} }
} }
for { for {
@@ -1023,11 +1041,12 @@ type WPPositionV struct {
PosOffset int64 `xml:"wp:posOffset"` PosOffset int64 `xml:"wp:posOffset"`
} }
// UnmarshalXML ...
func (r *WPPositionV) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *WPPositionV) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for _, attr := range start.Attr { for _, attr := range start.Attr {
switch attr.Name.Local { if attr.Name.Local == "relativeFrom" {
case "relativeFrom":
r.RelativeFrom = attr.Value r.RelativeFrom = attr.Value
break
} }
} }
for { for {

View File

@@ -13,6 +13,7 @@ type Hyperlink struct {
Run Run Run Run
} }
// UnmarshalXML ...
func (r *Hyperlink) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *Hyperlink) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()

View File

@@ -6,11 +6,13 @@ import (
"strings" "strings"
) )
// ParagraphProperties <w:pPr>
type ParagraphProperties struct { type ParagraphProperties struct {
XMLName xml.Name `xml:"w:pPr,omitempty"` XMLName xml.Name `xml:"w:pPr,omitempty"`
Justification *Justification `xml:"w:jc,omitempty"` Justification *Justification `xml:"w:jc,omitempty"`
} }
// UnmarshalXML ...
func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -34,6 +36,7 @@ func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElemen
} }
// Paragraph <w:p>
type Paragraph struct { type Paragraph struct {
// XMLName xml.Name `xml:"w:p,omitempty"` // XMLName xml.Name `xml:"w:p,omitempty"`
Properties *ParagraphProperties Properties *ParagraphProperties
@@ -89,6 +92,7 @@ func (p *Paragraph) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeToken(start.End()) return e.EncodeToken(start.End())
} }
// UnmarshalXML ...
func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
children := make([]interface{}, 0, 64) children := make([]interface{}, 0, 64)
for { for {

View File

@@ -12,12 +12,14 @@ const (
REL_TARGETMODE = "External" REL_TARGETMODE = "External"
) )
// Relationships ...
type Relationships struct { type Relationships struct {
mu sync.RWMutex mu sync.RWMutex
Xmlns string `xml:"xmlns,attr"` Xmlns string `xml:"xmlns,attr"`
Relationship []Relationship Relationship []Relationship
} }
// Relationship ...
type Relationship struct { type Relationship struct {
ID string `xml:"Id,attr"` ID string `xml:"Id,attr"`
Type string `xml:"Type,attr"` Type string `xml:"Type,attr"`

View File

@@ -11,7 +11,7 @@ import (
type Run struct { type Run struct {
XMLName xml.Name `xml:"w:r,omitempty"` XMLName xml.Name `xml:"w:r,omitempty"`
RunProperties *RunProperties `xml:"w:rPr,omitempty"` RunProperties *RunProperties `xml:"w:rPr,omitempty"`
FrontTab []struct { // TODO: replace with variable []RunChild FrontTab []struct { //TODO: replace with variable []RunChild
XMLName xml.Name `xml:"w:tab,omitempty"` XMLName xml.Name `xml:"w:tab,omitempty"`
} }
InstrText string `xml:"w:instrText,omitempty"` InstrText string `xml:"w:instrText,omitempty"`
@@ -22,6 +22,7 @@ type Run struct {
} }
} }
// UnmarshalXML ...
func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -97,6 +98,7 @@ type RunProperties struct {
Style *Style `xml:"w:pStyle,omitempty"` Style *Style `xml:"w:pStyle,omitempty"`
} }
// UnmarshalXML ...
func (r *RunProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *RunProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()

View File

@@ -7,11 +7,14 @@ import (
// Text object contains the actual text // Text object contains the actual text
type Text struct { type Text struct {
XMLName xml.Name `xml:"w:t,omitempty"` XMLName xml.Name `xml:"w:t,omitempty"`
XMLSpace string `xml:"xml:space,attr,omitempty"`
Text string `xml:",chardata"` // XMLSpace string `xml:"xml:space,attr,omitempty"`
Text string `xml:",chardata"`
} }
// UnmarshalXML ...
func (r *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (r *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for { for {
t, err := d.Token() t, err := d.Token()
@@ -22,8 +25,7 @@ func (r *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return err return err
} }
switch tt := t.(type) { if tt, ok := t.(xml.CharData); ok {
case xml.CharData:
r.Text = string(tt) // implicitly copy r.Text = string(tt) // implicitly copy
} }

View File

@@ -76,12 +76,14 @@ func (f *Docx) parseDocRelation(file *zip.File) error {
} }
defer zf.Close() defer zf.Close()
f.DocRelation.Xmlns = XMLNS_R f.docRelation.Xmlns = XMLNS_R
//TODO: find last rId & imageId //TODO: find last rID
return xml.NewDecoder(zf).Decode(&f.DocRelation) return xml.NewDecoder(zf).Decode(&f.docRelation)
} }
// parseMedia add the media into Docx struct
func (f *Docx) parseMedia(file *zip.File) error { func (f *Docx) parseMedia(file *zip.File) error {
//TODO: find last imageID
name := file.Name[len(MEDIA_FOLDER):] name := file.Name[len(MEDIA_FOLDER):]
zf, err := file.Open() zf, err := file.Open()
if err != nil { if err != nil {