2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
import "errors"
|
|
|
|
|
|
|
|
type PlainText struct {
|
|
|
|
*CommonAttributes
|
|
|
|
Type string `xml:"type,attr,omitempty"` // Must be text or html
|
|
|
|
Text string `xml:"text"`
|
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// isText checks whether the PlainText is a Text. It returns a bool.
|
2024-10-16 18:31:24 +02:00
|
|
|
func (p *PlainText) isText() bool { return true }
|
2024-10-13 17:19:40 +02:00
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// Check checks the PlainText for incompatibilities with RFC4287. It returns an
|
|
|
|
// error.
|
2024-10-13 17:19:40 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2024-10-16 16:51:39 +02:00
|
|
|
if p.Type == "html" && !isCorrectlyEscaped(p.Text) {
|
|
|
|
return errors.New("text element of plain text not correctly escaped")
|
|
|
|
}
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
if p.Text == "" {
|
|
|
|
return errors.New("text element of plain text empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|