From 0c30fd09304b17fdb42b0dcea142962b2f4883a3 Mon Sep 17 00:00:00 2001 From: sanbai <42755810+sanbaiw@users.noreply.github.com> Date: Tue, 6 May 2025 16:50:32 +0800 Subject: [PATCH] feat: add support for number properties in paragraph unmarshaling (#50) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zhihhwang Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com> --- structpara.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/structpara.go b/structpara.go index 8b5d31e..6f5ecc6 100644 --- a/structpara.go +++ b/structpara.go @@ -24,6 +24,7 @@ import ( "encoding/xml" "io" "reflect" + "strconv" "strings" ) @@ -109,6 +110,13 @@ func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) e p.RunProperties = &value case "pStyle": p.Style = &Style{Val: getAtt(tt.Attr, "val")} + case "numPr": + var value NumProperties + err = d.DecodeElement(&value, &tt) + if err != nil && !strings.HasPrefix(err.Error(), "expected") { + return err + } + p.NumProperties = &value case "textAlignment": p.TextAlignment = &TextAlignment{Val: getAtt(tt.Attr, "val")} case "adjustRightInd": @@ -155,6 +163,7 @@ func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) e return err } p.OverflowPunct = &value + default: err = d.Skip() // skip unsupported tags if err != nil { @@ -184,6 +193,12 @@ type Paragraph struct { func (p *Paragraph) String() string { sb := strings.Builder{} + if p.Properties != nil && p.Properties.NumProperties != nil && p.Properties.NumProperties.Ilvl != nil { + indent, err := strconv.Atoi(p.Properties.NumProperties.Ilvl.Val) + if err == nil { + sb.WriteString(strings.Repeat(" ", indent*2)) + } + } for _, c := range p.Children { switch o := c.(type) { case *Hyperlink: