Compare commits
No commits in common. "2a4adec6bdaee08dd8bdda0af6d5887b5d492f53" and "2d1d95502f495413a780fcb7a154e14828f08d53" have entirely different histories.
2a4adec6bd
...
2d1d95502f
13
text.go
13
text.go
@ -2,7 +2,6 @@ package atomfeed
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Text interface {
|
type Text interface {
|
||||||
@ -12,18 +11,10 @@ type Text interface {
|
|||||||
|
|
||||||
func NewText(textType, content string) (Text, error) {
|
func NewText(textType, content string) (Text, error) {
|
||||||
switch textType {
|
switch textType {
|
||||||
case "text":
|
case "text", "html":
|
||||||
return &PlainText{Type: textType, Text: content}, nil
|
return &PlainText{Type: textType, Text: content}, nil
|
||||||
case "html":
|
|
||||||
return &PlainText{Type: textType, Text: html.EscapeString(content)}, nil
|
|
||||||
case "xhtml":
|
case "xhtml":
|
||||||
return &XHTMLText{
|
return &XHTMLText{Type: textType, XHTMLDiv: content}, nil
|
||||||
Type: textType,
|
|
||||||
XHTMLDiv: XHTMLDiv{
|
|
||||||
XMLNS: "http://www.w3.org/1999/xhtml",
|
|
||||||
Content: content,
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
case "":
|
case "":
|
||||||
return &PlainText{Type: "text", Text: content}, nil
|
return &PlainText{Type: "text", Text: content}, nil
|
||||||
default:
|
default:
|
||||||
|
17
xhtmlText.go
17
xhtmlText.go
@ -1,20 +1,11 @@
|
|||||||
package atomfeed
|
package atomfeed
|
||||||
|
|
||||||
import (
|
import "errors"
|
||||||
"encoding/xml"
|
|
||||||
"errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
type XHTMLDiv struct {
|
|
||||||
XMLName xml.Name `xml:"div"`
|
|
||||||
XMLNS string `xml:"xmlns,attr"`
|
|
||||||
Content string `xml:",innerxml"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type XHTMLText struct {
|
type XHTMLText struct {
|
||||||
*CommonAttributes
|
*CommonAttributes
|
||||||
Type string `xml:"type,attr"` // Must be xhtml
|
Type string `xml:"type,attr"` // Must be xhtml
|
||||||
XHTMLDiv XHTMLDiv
|
XHTMLDiv string `xml:"div"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *XHTMLText) IsText() bool { return true }
|
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")
|
return errors.New("type attribute of xhtml text must be xhtml")
|
||||||
}
|
}
|
||||||
|
|
||||||
if x.XHTMLDiv.XMLNS != "http://www.w3.org/1999/xhtml" {
|
if x.XHTMLDiv == "" {
|
||||||
return errors.New("xmlns attribute of xhtml text must be http://www.w3.org/1999/xhtml")
|
return errors.New("xhtmlDiv element of xhtml text empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user