31 lines
580 B
Go
31 lines
580 B
Go
package atomfeed
|
|
|
|
import (
|
|
"fmt"
|
|
"html"
|
|
)
|
|
|
|
type Text interface {
|
|
isText() bool
|
|
Check() error
|
|
}
|
|
|
|
func NewText(textType, content string) (Text, error) {
|
|
switch textType {
|
|
case "text", "":
|
|
return &PlainText{Type: textType, Text: content}, nil
|
|
case "html":
|
|
return &PlainText{Type: textType, Text: html.UnescapeString(content)}, nil
|
|
case "xhtml":
|
|
return &XHTMLText{
|
|
Type: textType,
|
|
XHTMLDiv: XHTMLDiv{
|
|
XMLNS: "http://www.w3.org/1999/xhtml",
|
|
Content: content,
|
|
},
|
|
}, nil
|
|
default:
|
|
return nil, fmt.Errorf("%v is not a valid text type", textType)
|
|
}
|
|
}
|