diff --git a/apipara.go b/apipara.go index 15fe00d..eae5ea4 100644 --- a/apipara.go +++ b/apipara.go @@ -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 +} diff --git a/structnum.go b/structnum.go new file mode 100644 index 0000000..1a119ac --- /dev/null +++ b/structnum.go @@ -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 +} diff --git a/structsect.go b/structsect.go index 2298c88..cc66873 100644 --- a/structsect.go +++ b/structsect.go @@ -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"` @@ -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"` @@ -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 @@ -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 @@ -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