2024-10-13 17:19:40 +02:00
|
|
|
package atomfeed
|
|
|
|
|
2024-10-15 15:36:11 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
2024-10-15 16:01:40 +02:00
|
|
|
"html"
|
2024-10-15 15:36:11 +02:00
|
|
|
)
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
type Text interface {
|
|
|
|
Check() error
|
|
|
|
IsText() bool
|
|
|
|
}
|
2024-10-15 15:36:11 +02:00
|
|
|
|
|
|
|
func NewText(textType, content string) (Text, error) {
|
|
|
|
switch textType {
|
2024-10-15 16:01:40 +02:00
|
|
|
case "text":
|
2024-10-15 15:36:11 +02:00
|
|
|
return &PlainText{Type: textType, Text: content}, nil
|
2024-10-15 16:01:40 +02:00
|
|
|
case "html":
|
|
|
|
return &PlainText{Type: textType, Text: html.EscapeString(content)}, nil
|
2024-10-15 15:36:11 +02:00
|
|
|
case "xhtml":
|
2024-10-15 16:02:13 +02:00
|
|
|
return &XHTMLText{
|
|
|
|
Type: textType,
|
|
|
|
XHTMLDiv: XHTMLDiv{
|
|
|
|
XMLNS: "http://www.w3.org/1999/xhtml",
|
|
|
|
Content: content,
|
|
|
|
},
|
|
|
|
}, nil
|
2024-10-15 15:36:11 +02:00
|
|
|
case "":
|
|
|
|
return &PlainText{Type: "text", Text: content}, nil
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("%v is not a valid text type", textType)
|
|
|
|
}
|
|
|
|
}
|