2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
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 {
|
2024-10-16 18:31:24 +02:00
|
|
|
isText() bool
|
2024-10-13 17:19:40 +02:00
|
|
|
Check() error
|
|
|
|
}
|
2024-10-15 15:36:11 +02:00
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// NewText creates a new Text. It returns a Text and an error.
|
2024-10-15 15:36:11 +02:00
|
|
|
func NewText(textType, content string) (Text, error) {
|
|
|
|
switch textType {
|
2024-10-15 20:03:09 +02:00
|
|
|
case "text", "":
|
2024-10-15 20:09:18 +02:00
|
|
|
return &PlainText{Type: textType, Text: content}, nil
|
2024-10-15 16:01:40 +02:00
|
|
|
case "html":
|
2024-10-16 16:51:39 +02:00
|
|
|
return &PlainText{Type: textType, Text: html.UnescapeString(content)}, nil
|
2024-10-15 15:36:11 +02:00
|
|
|
case "xhtml":
|
2024-10-15 16:02:13 +02:00
|
|
|
return &XHTMLText{
|
|
|
|
Type: textType,
|
2024-10-17 19:44:27 +02:00
|
|
|
XHTMLDiv: &XHTMLDiv{
|
2024-10-15 16:02:13 +02:00
|
|
|
XMLNS: "http://www.w3.org/1999/xhtml",
|
|
|
|
Content: content,
|
|
|
|
},
|
|
|
|
}, nil
|
2024-10-15 15:36:11 +02:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("%v is not a valid text type", textType)
|
|
|
|
}
|
|
|
|
}
|