Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions decorators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ package draftjs
import "fmt"

type Decorator interface {
RenderBeginning(data map[string]string) string
RenderEnding(data map[string]string) string
RenderBeginning(data map[string]interface{}) string
RenderEnding(data map[string]interface{}) string
}

type LinkDecorator struct {
}

func (decorator *LinkDecorator) RenderBeginning(data map[string]string) string {
func (decorator *LinkDecorator) RenderBeginning(data map[string]interface{}) string {
return fmt.Sprintf("<a href=\"%s\" target=\"_blank\">", data["url"])
}

func (decorator *LinkDecorator) RenderEnding(data map[string]string) string {
func (decorator *LinkDecorator) RenderEnding(data map[string]interface{}) string {
return "</a>"
}

type ImageDecorator struct {
}

func (decorator *ImageDecorator) RenderBeginning(data map[string]string) string {
func (decorator *ImageDecorator) RenderBeginning(data map[string]interface{}) 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 {
func (decorator *ImageDecorator) RenderEnding(data map[string]interface{}) string {
return "</img>"
}
6 changes: 3 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type ContentBlock struct {
// Entity
// https://github.com/facebook/draft-js/blob/master/src/model/encoding/RawDraftEntity.js
type Entity struct {
Type string `json:"type"`
Mutability string `json:"mutability"`
Data map[string]string `json:"data"`
Type string `json:"type"`
Mutability string `json:"mutability"`
Data map[string]interface{} `json:"data"`
}

type Range struct {
Expand Down