Compare commits

..

No commits in common. "2a4adec6bdaee08dd8bdda0af6d5887b5d492f53" and "2d1d95502f495413a780fcb7a154e14828f08d53" have entirely different histories.

2 changed files with 6 additions and 24 deletions

13
text.go
View File

@ -2,7 +2,6 @@ package atomfeed
import (
"fmt"
"html"
)
type Text interface {
@ -12,18 +11,10 @@ type Text interface {
func NewText(textType, content string) (Text, error) {
switch textType {
case "text":
case "text", "html":
return &PlainText{Type: textType, Text: content}, nil
case "html":
return &PlainText{Type: textType, Text: html.EscapeString(content)}, nil
case "xhtml":
return &XHTMLText{
Type: textType,
XHTMLDiv: XHTMLDiv{
XMLNS: "http://www.w3.org/1999/xhtml",
Content: content,
},
}, nil
return &XHTMLText{Type: textType, XHTMLDiv: content}, nil
case "":
return &PlainText{Type: "text", Text: content}, nil
default:

View File

@ -1,20 +1,11 @@
package atomfeed
import (
"encoding/xml"
"errors"
)
type XHTMLDiv struct {
XMLName xml.Name `xml:"div"`
XMLNS string `xml:"xmlns,attr"`
Content string `xml:",innerxml"`
}
import "errors"
type XHTMLText struct {
*CommonAttributes
Type string `xml:"type,attr"` // Must be xhtml
XHTMLDiv XHTMLDiv
XHTMLDiv string `xml:"div"`
}
func (x *XHTMLText) IsText() bool { return true }
@ -24,8 +15,8 @@ func (x *XHTMLText) Check() error {
return errors.New("type attribute of xhtml text must be xhtml")
}
if x.XHTMLDiv.XMLNS != "http://www.w3.org/1999/xhtml" {
return errors.New("xmlns attribute of xhtml text must be http://www.w3.org/1999/xhtml")
if x.XHTMLDiv == "" {
return errors.New("xhtmlDiv element of xhtml text empty")
}
return nil