Skip to content

Commit 0c30fd0

Browse files
sanbaiwfumiama
andauthored
feat: add support for number properties in paragraph unmarshaling (#50)
Co-authored-by: zhihhwang <zhihhwang@tencent.com> Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
1 parent c6b0eac commit 0c30fd0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

structpara.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"encoding/xml"
2525
"io"
2626
"reflect"
27+
"strconv"
2728
"strings"
2829
)
2930

@@ -109,6 +110,13 @@ func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) e
109110
p.RunProperties = &value
110111
case "pStyle":
111112
p.Style = &Style{Val: getAtt(tt.Attr, "val")}
113+
case "numPr":
114+
var value NumProperties
115+
err = d.DecodeElement(&value, &tt)
116+
if err != nil && !strings.HasPrefix(err.Error(), "expected") {
117+
return err
118+
}
119+
p.NumProperties = &value
112120
case "textAlignment":
113121
p.TextAlignment = &TextAlignment{Val: getAtt(tt.Attr, "val")}
114122
case "adjustRightInd":
@@ -155,6 +163,7 @@ func (p *ParagraphProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) e
155163
return err
156164
}
157165
p.OverflowPunct = &value
166+
158167
default:
159168
err = d.Skip() // skip unsupported tags
160169
if err != nil {
@@ -184,6 +193,12 @@ type Paragraph struct {
184193

185194
func (p *Paragraph) String() string {
186195
sb := strings.Builder{}
196+
if p.Properties != nil && p.Properties.NumProperties != nil && p.Properties.NumProperties.Ilvl != nil {
197+
indent, err := strconv.Atoi(p.Properties.NumProperties.Ilvl.Val)
198+
if err == nil {
199+
sb.WriteString(strings.Repeat(" ", indent*2))
200+
}
201+
}
187202
for _, c := range p.Children {
188203
switch o := c.(type) {
189204
case *Hyperlink:

0 commit comments

Comments
 (0)