-
Notifications
You must be signed in to change notification settings - Fork 1
/
highlight.go
34 lines (28 loc) · 882 Bytes
/
highlight.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package elements
import "encoding/xml"
// Highlight represents the highlighting of a text or element.
type Highlight struct {
Value ColorIndex
}
// NewHighlight creates a new Highlight.
func NewHighlight(value ColorIndex) *Highlight {
return &Highlight{Value: value}
}
// MarshalXML marshals Highlight to XML.
func (h *Highlight) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
start.Name.Local = "w:highlight"
start.Attr = append(start.Attr, xml.Attr{Name: xml.Name{Local: "w:val"}, Value: string(h.Value)})
return e.EncodeElement("", start)
}
// UnmarshalXML unmarshals XML to Highlight.
func (h *Highlight) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var attr string
for _, a := range start.Attr {
if a.Name.Local == "val" {
attr = a.Value
break
}
}
h.Value = ColorIndex(attr)
return d.Skip() // Skipping the inner content
}