-
Notifications
You must be signed in to change notification settings - Fork 1
/
html.go
32 lines (25 loc) · 670 Bytes
/
html.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
package gortf
func RTFToHTML(r *RtfDocument) (string, error) {
body := r.Body
var htmlBody string
for _, styleBlock := range body {
closingTagStack := []string{}
if styleBlock.Painter.Bold {
htmlBody += "<bold>"
closingTagStack = append(closingTagStack, "</bold>")
}
if styleBlock.Painter.Italic {
htmlBody += "<italic>"
closingTagStack = append(closingTagStack, "</italic>")
}
if styleBlock.Painter.Underline {
htmlBody += "<u>"
closingTagStack = append(closingTagStack, "</u>")
}
htmlBody += styleBlock.Text
for i := len(closingTagStack) - 1; i >= 0; i-- {
htmlBody += closingTagStack[i]
}
}
return htmlBody, nil
}