atom/inlineXHTMLContent.go
2024-10-17 19:44:27 +02:00

53 lines
1.5 KiB
Go

package atom
import (
"errors"
"fmt"
)
type InlineXHTMLContent struct {
*CommonAttributes
XHTMLDiv *XHTMLDiv
Type string `xml:"type,attr"`
}
// newInlineXHTMLContent creates a new InlineXHTMLContent. It returns a
// *InlineXHTMLContent and an error.
func newInlineXHTMLContent(mediaType string, content any) (*InlineXHTMLContent, error) {
if mediaType != "xhtml" {
return nil, fmt.Errorf("media type %v incompatible with inline xhtml content", mediaType)
}
xhtmlDiv, ok := content.(*XHTMLDiv)
if !ok {
return nil, fmt.Errorf("content type %T incompatible with inline xhtml content", content)
}
return &InlineXHTMLContent{Type: mediaType, XHTMLDiv: xhtmlDiv}, nil
}
// isContent checks whether the InlineXHTMLContent is a Content. It returns a
// bool.
func (i *InlineXHTMLContent) isContent() bool { return true }
// hasSRC checks whether the InlineXHTMLContent has a SRC attribute. It returns
// a bool.
func (i *InlineXHTMLContent) hasSRC() bool { return false }
// getType returns the Type of the InlineXHTMLContent as a string.
func (i *InlineXHTMLContent) getType() string { return i.Type }
// Check checks the InlineXHTMLContent for incompatibilities with RFC4287. It
// returns an error.
func (i *InlineXHTMLContent) Check() error {
if i.Type != "xhtml" {
return errors.New("type attribute of inline xhtml content must be xhtml")
}
if err := i.XHTMLDiv.Check(); err != nil {
return fmt.Errorf("xhtml div element %v of inline xhtml content %v: %v", i.XHTMLDiv, i, err)
}
return nil
}