diff --git a/oxml/elements/paragraph.go b/oxml/elements/paragraph.go index 9d12d11..dc4db54 100644 --- a/oxml/elements/paragraph.go +++ b/oxml/elements/paragraph.go @@ -38,8 +38,12 @@ func DefaultParagraphChild() *ParagraphChild { return &ParagraphChild{} } -func (p *Paragraph) GetType() string { - return "p" +func (p *Paragraph) Style(value string) *Paragraph { + if p.Property == nil { + p.Property = DefaultParaProperty() + } + p.Property.Style = NewParagraphStyle(value) + return p } func (p *Paragraph) Numbering(id int, level int) { diff --git a/oxml/elements/run.go b/oxml/elements/run.go index f517bc8..c216551 100644 --- a/oxml/elements/run.go +++ b/oxml/elements/run.go @@ -99,6 +99,11 @@ func (r *Run) Underline(value UnderlineStyle) *Run { return r } +func (r *Run) Style(value string) *Run { + r.RunProperty.Style = NewRunStyle(value) + return r +} + func (r *Run) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { start.Name.Local = "w:r" diff --git a/oxml/elements/text.go b/oxml/elements/text.go index 2247129..e0f5e2e 100644 --- a/oxml/elements/text.go +++ b/oxml/elements/text.go @@ -6,19 +6,27 @@ import ( ) type Text struct { - text string + text string + preserveSpace bool } func NewText() *Text { - return &Text{} + return &Text{ + preserveSpace: true, + } } func TextFromString(text string) *Text { - return &Text{text: text} + return &Text{text: text, preserveSpace: true} } func (t *Text) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { elem := xml.StartElement{Name: xml.Name{Local: "w:t"}} + + if t.preserveSpace { + elem.Attr = append(elem.Attr, xml.Attr{Name: xml.Name{Local: "xml:space"}, Value: "preserve"}) + } + if err = e.EncodeElement(t.text, elem); err != nil { return err } @@ -29,6 +37,13 @@ func (t *Text) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error) { func (t *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { var buf bytes.Buffer + for _, attr := range start.Attr { + if attr.Name.Local == "space" && attr.Value == "preserve" { + t.preserveSpace = true + break + } + } + for { token, err := d.Token() if err != nil {