atom/xhtmlText.go

42 lines
991 B
Go
Raw Normal View History

2024-10-16 21:28:04 +02:00
package atom
2024-10-13 17:19:40 +02:00
import (
"fmt"
)
2024-10-15 16:02:13 +02:00
2024-10-13 17:19:40 +02:00
type XHTMLText struct {
*CommonAttributes
2024-10-17 19:44:27 +02:00
XHTMLDiv *XHTMLDiv
2024-10-13 17:19:40 +02:00
Type string `xml:"type,attr"` // Must be xhtml
}
2024-10-16 19:59:28 +02:00
// isText checks whether the XHTMLText is a Text. It returns a bool.
2024-10-16 18:31:24 +02:00
func (x *XHTMLText) isText() bool { return true }
2024-10-13 17:19:40 +02:00
// newPlainText creates a new PlainText. It returns a *PlainText and an error.
func newXHTMLText(textType, content string) (*XHTMLText, error) {
xhtmlDiv, err := NewXHTMLDiv(content)
if err != nil {
return nil, fmt.Errorf("error creating new xhtml text: %v", err)
}
return &XHTMLText{
Type: textType,
XHTMLDiv: xhtmlDiv,
}, nil
}
2024-10-16 19:59:28 +02:00
// Check checks the XHTMLText for incompatibilities with RFC4287. It returns an
// error.
2024-10-13 17:19:40 +02:00
func (x *XHTMLText) Check() error {
if x.Type != "xhtml" {
2024-10-18 19:04:08 +02:00
return fmt.Errorf("type attribute of xhtml text %v must be xhtml", x)
2024-10-13 17:19:40 +02:00
}
2024-10-17 18:12:23 +02:00
if err := x.XHTMLDiv.Check(); err != nil {
return fmt.Errorf("xhtml div element %v of xhtml text %v: %v", x.XHTMLDiv, x, err)
2024-10-13 17:19:40 +02:00
}
return nil
}