2024-10-13 17:19:40 +02:00
|
|
|
package atomfeed
|
|
|
|
|
2024-10-15 20:47:16 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
)
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
type InlineTextContent struct {
|
|
|
|
*CommonAttributes
|
|
|
|
Type string `xml:"type,attr,omitempty"` // Must be text or html
|
|
|
|
Texts []string `xml:"texts,omitempty"`
|
|
|
|
}
|
|
|
|
|
2024-10-15 20:47:16 +02:00
|
|
|
func newInlineTextContent(mediaType string, content any) (*InlineTextContent, error) {
|
|
|
|
if mediaType != "text" && mediaType != "html" && mediaType != "" {
|
|
|
|
return nil, fmt.Errorf("media type %v incompatible with inline text content", mediaType)
|
|
|
|
}
|
|
|
|
|
|
|
|
texts := make([]string, 0)
|
|
|
|
|
|
|
|
t := reflect.TypeOf(content)
|
|
|
|
switch t.Kind() {
|
|
|
|
case reflect.Slice:
|
|
|
|
if t.Elem().Kind() == reflect.String {
|
|
|
|
for _, t := range content.([]string) {
|
|
|
|
texts = append(texts, t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case reflect.String:
|
|
|
|
texts = append(texts, content.(string))
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("content type %T incompatible with inline text content", content)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &InlineTextContent{Type: mediaType, Texts: texts}, nil
|
|
|
|
}
|
|
|
|
|
2024-10-15 20:52:35 +02:00
|
|
|
func (i *InlineTextContent) isContent() bool { return true }
|
|
|
|
|
|
|
|
func (i *InlineTextContent) hasSRC() bool { return false }
|
|
|
|
|
|
|
|
func (i *InlineTextContent) getType() string { return i.Type }
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
func (i *InlineTextContent) Check() error {
|
|
|
|
if i.Type != "" && i.Type != "text" && i.Type != "html" {
|
|
|
|
return errors.New("type attribute of inline text content must be text or html if not omitted")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|