From 72447243cf30bd8ae3eb2c8a1c09329b30fa8759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sun, 17 Mar 2024 20:05:37 +0900 Subject: [PATCH] fix(#21): br decoding --- structrun.go | 6 +++--- structtext.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/structrun.go b/structrun.go index 4160595..1c97952 100644 --- a/structrun.go +++ b/structrun.go @@ -117,12 +117,12 @@ func (r *Run) parse(d *xml.Decoder, tt xml.StartElement) (child interface{}, err case "tab": child = &Tab{} case "br": - var brvalue BarterRabbet - err = d.DecodeElement(&brvalue, &tt) + var value BarterRabbet + err = d.DecodeElement(&value, &tt) if err != nil { return nil, err } - child = &brvalue + child = &value case "AlternateContent": /*var value AlternateContent value.file = r.file diff --git a/structtext.go b/structtext.go index c3fe016..5deff41 100644 --- a/structtext.go +++ b/structtext.go @@ -94,6 +94,19 @@ type BarterRabbet struct { Type string `xml:"w:type,attr,omitempty"` } +// UnmarshalXML ... +func (f *BarterRabbet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + for _, attr := range start.Attr { + switch attr.Name.Local { + case "type": + f.Type = attr.Value + } + } + // Consume the end element + _, err := d.Token() + return err +} + // Text object contains the actual text type Text struct { XMLName xml.Name `xml:"w:t,omitempty"`