forked from nploi/draftjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decorators.go
126 lines (94 loc) · 3.35 KB
/
decorators.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package draftjs
import (
"fmt"
)
type Decorator interface {
RenderBeginning(data map[string]string) string
RenderEnding(data map[string]string) string
}
type LinkDecorator struct {
}
func (decorator *LinkDecorator) RenderBeginning(data map[string]string) string {
return fmt.Sprintf("<a href=\"%s\" target=\"_blank\">", data["url"])
}
func (decorator *LinkDecorator) RenderEnding(data map[string]string) string {
return "</a>"
}
type ImageDecorator struct {
}
func (decorator *ImageDecorator) RenderBeginning(data map[string]string) string {
maxHeightStr := GetMaxHeightStyle()
if alt, ok := data["alt"]; ok {
return fmt.Sprintf("<img%s src=\"%s\" alt=\"%s\">", data["data"], maxHeightStr, alt)
}
return fmt.Sprintf("<img%s src=\"%s\">", maxHeightStr, data["data"])
}
func (decorator *ImageDecorator) RenderEnding(data map[string]string) string {
return "</img>"
}
type BlockImageDecorator struct {
}
func (decorator *BlockImageDecorator) RenderBeginning(data map[string]string) string {
maxHeightStr := GetMaxHeightStyle()
if alt, ok := data["alt"]; ok {
return fmt.Sprintf("<figure><img%s src=\"%s\" alt=\"%s\">", maxHeightStr, data["data"], alt)
}
return fmt.Sprintf("<figure><img%s src=\"%s\">", maxHeightStr, data["data"])
}
func (decorator *BlockImageDecorator) RenderEnding(data map[string]string) string {
return "</img></figure>"
}
type InlineImageDecorator struct {
}
func (decorator *InlineImageDecorator) RenderBeginning(data map[string]string) string {
maxHeightStr := GetMaxHeightStyle()
if alt, ok := data["alt"]; ok {
return fmt.Sprintf("<img%s src=%s alt=\"%s\">", maxHeightStr, data["data"], alt)
}
return fmt.Sprintf("<img%s src=%s>", maxHeightStr, data["data"])
}
func (decorator *InlineImageDecorator) RenderEnding(data map[string]string) string {
return "</img>"
}
type BlockAudioDecorator struct {
}
func (decorator *BlockAudioDecorator) RenderBeginning(data map[string]string) string {
return fmt.Sprintf("<figure><audio controls><source src=\"%s\" type=\"audio/mpeg\">", data["data"])
}
func (decorator *BlockAudioDecorator) RenderEnding(data map[string]string) string {
return "</audio></figure>"
}
type InlineAudioDecorator struct {
}
func (decorator *InlineAudioDecorator) RenderBeginning(data map[string]string) string {
return fmt.Sprintf("<audio controls><source src=\"%s\" type=\"audio/mpeg\">", data["data"])
}
func (decorator *InlineAudioDecorator) RenderEnding(data map[string]string) string {
return "</audio>"
}
type AudioDecorator struct {
}
func (decorator *AudioDecorator) RenderBeginning(data map[string]string) string {
return fmt.Sprintf("<audio controls><source src=\"%s\" type=\"audio/mpeg\">", data["data"])
}
func (decorator *AudioDecorator) RenderEnding(data map[string]string) string {
return "</audio>"
}
type BlockMathJaxDecorator struct {
}
func (decorator *BlockMathJaxDecorator) RenderBeginning(data map[string]string) string {
latex := GetMathJaxData(data["data"])
return fmt.Sprintf("\\[%s\\]", latex)
}
func (decorator *BlockMathJaxDecorator) RenderEnding(data map[string]string) string {
return ""
}
type InlineMathJaxDecorator struct {
}
func (decorator *InlineMathJaxDecorator) RenderBeginning(data map[string]string) string {
latex := GetMathJaxData(data["data"])
return fmt.Sprintf("\\(%s\\)", latex)
}
func (decorator *InlineMathJaxDecorator) RenderEnding(data map[string]string) string {
return ""
}