Skip to content

Commit

Permalink
Merge branch 'pgmar'
Browse files Browse the repository at this point in the history
# Conflicts:
#	structsect.go
  • Loading branch information
guoqiang committed Dec 23, 2024
2 parents 9a86ceb + 3d1b7bf commit b2ba179
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apipara.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,16 @@ func (p *Paragraph) Style(val string) *Paragraph {
p.Properties.Style = &Style{Val: val}
return p
}

// NumPr number properties
func (p *Paragraph) NumPr(val string) *Paragraph {
if p.Properties == nil {
p.Properties = &ParagraphProperties{}
}
p.Properties.NumProperties = &NumProperties{
NumId: &NumId{
Val: val,
},
}
return p
}
59 changes: 59 additions & 0 deletions structnum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package docx

import (
"encoding/xml"
"io"
)

// NumProperties show the number properties
type NumProperties struct {
XMLName xml.Name `xml:"w:numPr,omitempty"`
NumId *NumId
Ilvl *Ilevel
}

// NumId show the number id
type NumId struct {
XMLName xml.Name `xml:"w:numId,omitempty"`
Val string `xml:"w:val,attr"`
}

// Ilevel show the level
type Ilevel struct {
XMLName xml.Name `xml:"w:ilvl,omitempty"`
Val string `xml:"w:val,attr"`
}

// UnmarshalXML ...
func (n *NumProperties) UnmarshalXML(d *xml.Decoder, _ xml.StartElement) error {
for {
t, err := d.Token()
if err == io.EOF {
break
}
if err != nil {
return err
}

if tt, ok := t.(xml.StartElement); ok {
switch tt.Name.Local {
case "numId":
var value NumId
value.Val = getAtt(tt.Attr, "val")
n.NumId = &value
case "ilvl":
var value Ilevel
value.Val = getAtt(tt.Attr, "val")
n.Ilvl = &value
default:
err = d.Skip() // skip unsupported tags
if err != nil {
return err
}
continue
}
}
}

return nil
}
6 changes: 6 additions & 0 deletions structsect.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type PgSz struct {
H int `xml:"w:h,attr"` // high of paper
}

// PgMar show the page margin
type PgMar struct {
Top int `xml:"w:top,attr"`
Left int `xml:"w:left,attr"`
Expand All @@ -49,10 +50,12 @@ type PgMar struct {
Gutter int `xml:"w:gutter,attr"`
}

// Cols show the number of columns
type Cols struct {
Space int `xml:"w:space,attr"`
}

// DocGrid show the document grid
type DocGrid struct {
Type string `xml:"w:type,attr"`
LinePitch int `xml:"w:linePitch,attr"`
Expand Down Expand Up @@ -134,6 +137,7 @@ func (pgsz *PgSz) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return err
}

// UnmarshalXML ...
func (pgmar *PgMar) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var err error

Expand Down Expand Up @@ -183,6 +187,7 @@ func (pgmar *PgMar) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return err
}

// UnmarshalXML ...
func (cols *Cols) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var err error

Expand All @@ -202,6 +207,7 @@ func (cols *Cols) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return err
}

// UnmarshalXML ...
func (dg *DocGrid) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var err error

Expand Down

0 comments on commit b2ba179

Please sign in to comment.