-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdecorators.go
More file actions
33 lines (25 loc) · 809 Bytes
/
decorators.go
File metadata and controls
33 lines (25 loc) · 809 Bytes
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
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["src"], alt)
}
return fmt.Sprintf("<img src=\"%s\">", data["src"])
}
func (decorator *ImageDecorator) RenderEnding(data map[string]string) string {
return "</img>"
}