-
Notifications
You must be signed in to change notification settings - Fork 1
/
document.go
70 lines (58 loc) · 1.25 KB
/
document.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package gortf
import (
"encoding/json"
"strings"
"time"
)
type RtfInformationGroup struct {
Title string
Subject string
Author string
Manager string
Company string
Operator string
Category string
Keywords string
Comment string
Version int
DocumentComment string
BaseAddress string
CreationTime *time.Time
RevisionTime *time.Time
LastPrintTime *time.Time
BackupTime *time.Time
}
type RtfDocument struct {
Header RtfHeader
InformationGroup RtfInformationGroup
Body []StyleBlock
}
func (r RtfDocument) String() string {
b, _ := json.Marshal(r)
return string(b)
}
func (r *RtfDocument) pushToBody(sb StyleBlock) {
r.Body = append(r.Body, sb)
}
func (r *RtfDocument) popFromBody() StyleBlock {
if len(r.Body) == 0 {
panic("too many group endings")
}
index := len(r.Body) - 1
element := r.Body[index]
r.Body = r.Body[:index]
return element
}
func (r *RtfDocument) ToText() (string, error) {
var sb strings.Builder
for _, b := range r.Body {
_, err := sb.WriteString(b.Text)
if err != nil {
return "", err
}
}
return sb.String(), nil
}
func (r *RtfDocument) ToHTML() (string, error) {
return RTFToHTML(r)
}