Compare commits
2 Commits
2d1d95502f
...
2a4adec6bd
Author | SHA1 | Date | |
---|---|---|---|
2a4adec6bd | |||
2cbc604d85 |
13
text.go
13
text.go
@ -2,6 +2,7 @@ package atomfeed
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Text interface {
|
type Text interface {
|
||||||
@ -11,10 +12,18 @@ type Text interface {
|
|||||||
|
|
||||||
func NewText(textType, content string) (Text, error) {
|
func NewText(textType, content string) (Text, error) {
|
||||||
switch textType {
|
switch textType {
|
||||||
case "text", "html":
|
case "text":
|
||||||
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{Type: textType, XHTMLDiv: content}, nil
|
return &XHTMLText{
|
||||||
|
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,11 +1,20 @@
|
|||||||
package atomfeed
|
package atomfeed
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"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 string `xml:"div"`
|
XHTMLDiv XHTMLDiv
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *XHTMLText) IsText() bool { return true }
|
func (x *XHTMLText) IsText() bool { return true }
|
||||||
@ -15,8 +24,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 == "" {
|
if x.XHTMLDiv.XMLNS != "http://www.w3.org/1999/xhtml" {
|
||||||
return errors.New("xhtmlDiv element of xhtml text empty")
|
return errors.New("xmlns attribute of xhtml text must be http://www.w3.org/1999/xhtml")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user