atom/plainText.go

31 lines
788 B
Go

package atom
import "errors"
type PlainText struct {
*CommonAttributes
Type string `xml:"type,attr,omitempty"` // Must be text or html
Text string `xml:"text"`
}
// isText checks whether the PlainText is a Text. It returns a bool.
func (p *PlainText) isText() bool { return true }
// Check checks the PlainText for incompatibilities with RFC4287. It returns an
// error.
func (p *PlainText) Check() error {
if p.Type != "" && p.Type != "text" && p.Type != "html" {
return errors.New("type attribute of plain text must be text or html if not omitted")
}
if p.Type == "html" && !isCorrectlyEscaped(p.Text) {
return errors.New("text element of plain text not correctly escaped")
}
if p.Text == "" {
return errors.New("text element of plain text empty")
}
return nil
}