atom/inlineTextContent.go

41 lines
1.2 KiB
Go
Raw Normal View History

2024-10-16 21:28:04 +02:00
package atom
2024-10-13 17:19:40 +02:00
2024-10-15 20:47:16 +02:00
import (
2024-10-17 20:10:18 +02:00
"encoding/xml"
2024-10-15 20:47:16 +02:00
"fmt"
)
2024-10-13 17:19:40 +02:00
type InlineTextContent struct {
2024-10-17 20:10:18 +02:00
XMLName xml.Name `xml:"content"`
2024-10-13 17:19:40 +02:00
*CommonAttributes
2024-10-17 17:33:33 +02:00
Type string `xml:"type,attr,omitempty"` // Must be text or html
Text string `xml:",chardata"`
2024-10-13 17:19:40 +02:00
}
2024-10-16 19:59:28 +02:00
// newInlineTextContent creates a new InlineTextContent. It returns a
// *InlineTextContent.
func newInlineTextContent(mediaType, text string) *InlineTextContent {
return &InlineTextContent{Type: mediaType, Text: text}
2024-10-15 20:47:16 +02:00
}
2024-10-16 19:59:28 +02:00
// isContent checks whether the InlineTextContent is a Content. It returns a
// bool.
2024-10-15 20:52:35 +02:00
func (i *InlineTextContent) isContent() bool { return true }
2024-10-16 19:59:28 +02:00
// hasSRC checks whether the InlineTextContent has a SRC attribute. It returns
// a bool.
2024-10-15 20:52:35 +02:00
func (i *InlineTextContent) hasSRC() bool { return false }
2024-10-16 19:59:28 +02:00
// getType returns the Type of the InlineTextContent as a string.
2024-10-15 20:52:35 +02:00
func (i *InlineTextContent) getType() string { return i.Type }
2024-10-16 19:59:28 +02:00
// Check checks the InlineTextContent for incompatibilities with RFC4287. It
// returns an error.
2024-10-13 17:19:40 +02:00
func (i *InlineTextContent) Check() error {
if i.Type != "" && i.Type != "text" && i.Type != "html" {
2024-10-18 19:04:08 +02:00
return fmt.Errorf("type attribute of inline text content %v must be text or html if not omitted", i)
2024-10-13 17:19:40 +02:00
}
return nil
}