Simplify NewText
This commit is contained in:
parent
987feb8226
commit
068f61dc2c
6
text.go
6
text.go
@ -12,8 +12,8 @@ type Text interface {
|
|||||||
|
|
||||||
func NewText(textType, content string) (Text, error) {
|
func NewText(textType, content string) (Text, error) {
|
||||||
switch textType {
|
switch textType {
|
||||||
case "text":
|
case "text", "":
|
||||||
return &PlainText{Type: textType, Text: content}, nil
|
return &PlainText{Type: "text", Text: content}, nil
|
||||||
case "html":
|
case "html":
|
||||||
return &PlainText{Type: textType, Text: html.EscapeString(content)}, nil
|
return &PlainText{Type: textType, Text: html.EscapeString(content)}, nil
|
||||||
case "xhtml":
|
case "xhtml":
|
||||||
@ -24,8 +24,6 @@ func NewText(textType, content string) (Text, error) {
|
|||||||
Content: content,
|
Content: content,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
case "":
|
|
||||||
return &PlainText{Type: "text", Text: content}, nil
|
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("%v is not a valid text type", textType)
|
return nil, fmt.Errorf("%v is not a valid text type", textType)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user