49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package atom
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
type InlineTextContent struct {
|
|
*CommonAttributes
|
|
Type string `xml:"type,attr,omitempty"` // Must be text or html
|
|
Text string `xml:",chardata"`
|
|
}
|
|
|
|
// newInlineTextContent creates a new InlineTextContent. It returns a
|
|
// *InlineTextContent and an error.
|
|
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)
|
|
}
|
|
|
|
text, ok := content.(string)
|
|
if !ok {
|
|
return nil, fmt.Errorf("content type %T incompatible with inline text content", content)
|
|
}
|
|
|
|
return &InlineTextContent{Type: mediaType, Text: text}, nil
|
|
}
|
|
|
|
// isContent checks whether the InlineTextContent is a Content. It returns a
|
|
// bool.
|
|
func (i *InlineTextContent) isContent() bool { return true }
|
|
|
|
// hasSRC checks whether the InlineTextContent has a SRC attribute. It returns
|
|
// a bool.
|
|
func (i *InlineTextContent) hasSRC() bool { return false }
|
|
|
|
// getType returns the Type of the InlineTextContent as a string.
|
|
func (i *InlineTextContent) getType() string { return i.Type }
|
|
|
|
// Check checks the InlineTextContent for incompatibilities with RFC4287. It
|
|
// returns an error.
|
|
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
|
|
}
|