forked from ejilay/draftjs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecorators.go
80 lines (60 loc) · 2 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
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 {
if alt, ok := data["alt"]; ok {
return fmt.Sprintf("<img src=\"%s\" alt=\"%s\">", data["data"], alt)
}
return fmt.Sprintf("<img src=\"%s\">", data["data"])
}
func (decorator *ImageDecorator) RenderEnding(data map[string]string) string {
return "</img>"
}
type ImageDecoratorV2 struct {
}
func (decorator *ImageDecoratorV2) RenderBeginning(data map[string]string) string {
if alt, ok := data["alt"]; ok {
return fmt.Sprintf("<img src=\"%s\" alt=\"%s\">", data["data"], alt)
}
return fmt.Sprintf("<img src=\"%s\">", data["data"])
}
func (decorator *ImageDecoratorV2) RenderEnding(data map[string]string) string {
return "</img>"
}
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 MathJaxDecorator struct {
}
func (decorator *MathJaxDecorator) RenderBeginning(data map[string]string) string {
return fmt.Sprintf("\\[%s\\]", data["data"])
}
func (decorator *MathJaxDecorator) RenderEnding(data map[string]string) string {
return ""
}
type InlineMathJaxDecorator struct {
}
func (decorator *InlineMathJaxDecorator) RenderBeginning(data map[string]string) string {
return fmt.Sprintf("\\(%s\\)", data["data"])
}
func (decorator *InlineMathJaxDecorator) RenderEnding(data map[string]string) string {
return ""
}