Compare commits
20 Commits
4b97bf7fdc
...
v0.2.2
Author | SHA1 | Date | |
---|---|---|---|
9445a7c4cd | |||
42416d13e7 | |||
b70ff82141 | |||
3172a4865a | |||
3b3f1f7e41 | |||
9c38048bd2 | |||
26e0c99150 | |||
6117876a59 | |||
cb61d90cae | |||
30623fdfe0 | |||
4ae8cecb17 | |||
8e226b48ef | |||
478d679985 | |||
d11b229691 | |||
e73b78ef30 | |||
5a82f1799f | |||
73624eadd8 | |||
17aa4b1a15 | |||
040d7a6b7b | |||
705b651f08 |
@ -1,4 +1,3 @@
|
||||
# atom-feed
|
||||
# atom
|
||||
|
||||
An extensible implementation of an Atom feed that aims to be very close to RFC4287.
|
||||
|
||||
|
6
atom.go
6
atom.go
@ -82,6 +82,12 @@ func isValidLanguageTag(tag LanguageTag) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// isValidAttribute checks whether an Attribute is valid. It returns a bool.
|
||||
func isValidAttribute(attribute string) bool {
|
||||
regex := regexp.MustCompile(`^[a-zA-Z0-9_]+="[^"]*"$`)
|
||||
return regex.MatchString(attribute)
|
||||
}
|
||||
|
||||
// NewURN generates an new valid IRI based on a UUID. It returns an IRI.
|
||||
func NewURN() IRI {
|
||||
return IRI(fmt.Sprint("urn:uuid:", uuid.New()))
|
||||
|
28
category.go
28
category.go
@ -1,27 +1,23 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
)
|
||||
|
||||
type Category struct {
|
||||
XMLName xml.Name `xml:"category"`
|
||||
*CommonAttributes
|
||||
Content Content `xml:"content"` // undefinedContent in RFC4287
|
||||
Term string `xml:"term,attr"`
|
||||
Scheme IRI `xml:"scheme,attr,omitempty"`
|
||||
Label string `xml:"label,attr,omitempty"`
|
||||
Term string `xml:"term,attr"`
|
||||
Scheme IRI `xml:"scheme,attr,omitempty"`
|
||||
Label string `xml:"label,attr,omitempty"`
|
||||
}
|
||||
|
||||
// NewCategory creates a new Category. It returns a *Category and an error.
|
||||
func NewCategory(term string) (*Category, error) {
|
||||
content, err := NewContent(InlineText, "", "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating content element: %v", err)
|
||||
}
|
||||
|
||||
return &Category{Term: term, Content: content}, nil
|
||||
// NewCategory creates a new Category. It returns a *Category.
|
||||
func NewCategory(term string) *Category {
|
||||
return &Category{Term: term}
|
||||
}
|
||||
|
||||
// SetLabel sets the label of the Category.
|
||||
@ -46,13 +42,5 @@ func (c *Category) Check() error {
|
||||
return fmt.Errorf("label attribute %v of category not correctly escaped", c.Label)
|
||||
}
|
||||
|
||||
if c.Content == nil {
|
||||
return errors.New("no content element of category")
|
||||
} else {
|
||||
if err := c.Content.Check(); err != nil {
|
||||
return fmt.Errorf("content element of category: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1,21 +1,27 @@
|
||||
package atom
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
type CommonAttributes struct {
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
UndefinedAttributes []*ExtensionAttribute `xml:",any"`
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
UndefinedAttributes []*xml.Attr `xml:",attr,omitempty"`
|
||||
}
|
||||
|
||||
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
|
||||
// returns an error.
|
||||
func (c *CommonAttributes) Check() error {
|
||||
for i, e := range c.UndefinedAttributes {
|
||||
if err := e.Check(); err != nil {
|
||||
return fmt.Errorf("extension attribute %v of common attributes: %v", i, err)
|
||||
}
|
||||
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
||||
// *CommonAttributes.
|
||||
func NewCommonAttributes() *CommonAttributes {
|
||||
return new(CommonAttributes)
|
||||
}
|
||||
|
||||
// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes.
|
||||
func (c *CommonAttributes) AddExtensionAttribute(name, value string) {
|
||||
if c.UndefinedAttributes == nil {
|
||||
c.UndefinedAttributes = make([]*xml.Attr, 1)
|
||||
c.UndefinedAttributes[0] = &xml.Attr{Name: xml.Name{Local: name}, Value: value}
|
||||
} else {
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
23
entry.go
23
entry.go
@ -1,6 +1,7 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@ -12,16 +13,17 @@ import (
|
||||
// a non-empty atom:summary element when the entry contains no atom:content
|
||||
// element.
|
||||
type Entry struct {
|
||||
XMLName xml.Name `xml:"entry"`
|
||||
*CommonAttributes
|
||||
Authors []*Person `xml:"author,omitempty"`
|
||||
Categories []*Category `xml:"category,omitempty"`
|
||||
Content Content `xml:"content,omitempty"`
|
||||
Contributors []*Person `xml:"contributors,omitempty"`
|
||||
ID *ID `xml:"id"`
|
||||
Links []*Link `xml:"link,omitempty"`
|
||||
Authors []*Person `xml:"author,omitempty"`
|
||||
Categories []*Category `xml:",omitempty"`
|
||||
Content Content `xml:",omitempty"`
|
||||
Contributors []*Person `xml:"contributors,omitempty"`
|
||||
ID *ID
|
||||
Links []*Link `xml:",omitempty"`
|
||||
Published *Date `xml:"published,omitempty"`
|
||||
Rights Text `xml:"rights,omitempty"`
|
||||
Source *Source `xml:"source,omitempty"`
|
||||
Source *Source `xml:",omitempty"`
|
||||
Summary Text `xml:"summary,omitempty"`
|
||||
Title Text `xml:"title"`
|
||||
Updated *Date `xml:"updated"`
|
||||
@ -62,8 +64,13 @@ func NewEntry(title string) (*Entry, error) {
|
||||
return nil, fmt.Errorf("error creating new entry: %v", err)
|
||||
}
|
||||
|
||||
id, err := NewID(NewURN())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating new entry: %v", err)
|
||||
}
|
||||
|
||||
return &Entry{
|
||||
ID: NewID(NewURN()),
|
||||
ID: id,
|
||||
Title: text,
|
||||
Updated: NewDate(time.Now()),
|
||||
}, nil
|
||||
|
@ -1,21 +0,0 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type ExtensionAttribute struct {
|
||||
Value any `xml:",attr"`
|
||||
XMLName xml.Name
|
||||
}
|
||||
|
||||
// Check checks the ExtensionAttribute for incompatibilities with RFC4287. It
|
||||
// returns an error.
|
||||
func (e *ExtensionAttribute) Check() error {
|
||||
if e.Value == nil {
|
||||
return errors.New("value element of extension attribute empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
25
feed.go
25
feed.go
@ -10,20 +10,20 @@ import (
|
||||
type Feed struct {
|
||||
XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"`
|
||||
*CommonAttributes
|
||||
Authors []*Person `xml:"author,omitempty"`
|
||||
Categories []*Category `xml:"category,omitempty"`
|
||||
Contributors []*Person `xml:"contributor,omitempty"`
|
||||
Generator *Generator `xml:"generator,omitempty"`
|
||||
Icon *Icon `xml:"icon,omitempty"`
|
||||
ID *ID `xml:"id"`
|
||||
Links []*Link `xml:"link,omitempty"`
|
||||
Logo *Logo `xml:"logo,omitempty"`
|
||||
Authors []*Person `xml:"author,omitempty"`
|
||||
Categories []*Category `xml:",omitempty"`
|
||||
Contributors []*Person `xml:"contributor,omitempty"`
|
||||
Generator *Generator `xml:",omitempty"`
|
||||
Icon *Icon `xml:",omitempty"`
|
||||
ID *ID
|
||||
Links []*Link `xml:",omitempty"`
|
||||
Logo *Logo `xml:",omitempty"`
|
||||
Rights Text `xml:"rights,omitempty"`
|
||||
Subtitle Text `xml:"subtitle,omitempty"`
|
||||
Title Text `xml:"title"`
|
||||
Updated *Date `xml:"updated"`
|
||||
Extensions []*ExtensionElement `xml:",any,omitempty"`
|
||||
Entries []*Entry `xml:"entry,omitempty"`
|
||||
Entries []*Entry `xml:",omitempty"`
|
||||
}
|
||||
|
||||
// NewFeed creates a new Feed. It returns a *Feed and an error.
|
||||
@ -33,8 +33,13 @@ func NewFeed(title string) (*Feed, error) {
|
||||
return nil, fmt.Errorf("error creating new feed: %v", err)
|
||||
}
|
||||
|
||||
id, err := NewID(NewURN())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating new feed: %v", err)
|
||||
}
|
||||
|
||||
return &Feed{
|
||||
ID: NewID(NewURN()),
|
||||
ID: id,
|
||||
Title: text,
|
||||
Updated: NewDate(time.Now()),
|
||||
}, nil
|
||||
|
@ -1,16 +1,18 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html"
|
||||
)
|
||||
|
||||
type Generator struct {
|
||||
XMLName xml.Name `xml:"generator"`
|
||||
*CommonAttributes
|
||||
URI IRI `xml:"uri,attr,omitempty"`
|
||||
Version string `xml:"version,attr,omitempty"`
|
||||
Text string `xml:"text"`
|
||||
Text string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// NewGenerator creates a new Generator. It returns a *Generator.
|
||||
|
14
icon.go
14
icon.go
@ -1,18 +1,24 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Icon struct {
|
||||
XMLName xml.Name `xml:"icon"`
|
||||
*CommonAttributes
|
||||
URI IRI `xml:"uri"`
|
||||
URI IRI `xml:",chardata"`
|
||||
}
|
||||
|
||||
// NewIcon creates a new Icon. It returns a *Icon.
|
||||
func NewIcon(uri string) *Icon {
|
||||
return &Icon{URI: IRI(uri)}
|
||||
// NewIcon creates a new Icon. It returns a *Icon and an error.
|
||||
func NewIcon(uri IRI) (*Icon, error) {
|
||||
if !isValidIRI(uri) {
|
||||
return nil, fmt.Errorf("uri %v not correctly formatted", uri)
|
||||
}
|
||||
|
||||
return &Icon{URI: uri}, nil
|
||||
}
|
||||
|
||||
// Check checks the Icon for incompatibilities with RFC4287. It returns an
|
||||
|
12
id.go
12
id.go
@ -1,18 +1,24 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type ID struct {
|
||||
XMLName xml.Name `xml:"id"`
|
||||
*CommonAttributes
|
||||
URI IRI `xml:",chardata"`
|
||||
}
|
||||
|
||||
// NewID creates a new ID. It returns a *ID.
|
||||
func NewID(id IRI) *ID {
|
||||
return &ID{URI: IRI(id)}
|
||||
// NewID creates a new ID. It returns a *ID and an error.
|
||||
func NewID(uri IRI) (*ID, error) {
|
||||
if !isValidIRI(uri) {
|
||||
return nil, fmt.Errorf("uri %v not correctly formatted", uri)
|
||||
}
|
||||
|
||||
return &ID{URI: IRI(uri)}, nil
|
||||
}
|
||||
|
||||
// Check checks the ID for incompatibilities with RFC4287. It returns an error.
|
||||
|
@ -1,12 +1,14 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
)
|
||||
|
||||
type InlineOtherContent struct {
|
||||
XMLName xml.Name `xml:"content"`
|
||||
*CommonAttributes
|
||||
AnyElement any `xml:",chardata"`
|
||||
Type MediaType `xml:"type,attr,omitempty"`
|
||||
|
@ -1,12 +1,13 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type InlineTextContent struct {
|
||||
XMLName xml.Name `xml:"content"`
|
||||
*CommonAttributes
|
||||
Type string `xml:"type,attr,omitempty"` // Must be text or html
|
||||
Text string `xml:",chardata"`
|
||||
@ -19,11 +20,12 @@ func newInlineTextContent(mediaType string, content any) (*InlineTextContent, er
|
||||
return nil, fmt.Errorf("media type %v incompatible with inline text content", mediaType)
|
||||
}
|
||||
|
||||
if reflect.TypeOf(content).Kind() != reflect.String {
|
||||
text, ok := content.(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("content type %T incompatible with inline text content", content)
|
||||
}
|
||||
|
||||
return &InlineTextContent{Type: mediaType, Text: content.(string)}, nil
|
||||
return &InlineTextContent{Type: mediaType, Text: text}, nil
|
||||
}
|
||||
|
||||
// isContent checks whether the InlineTextContent is a Content. It returns a
|
||||
|
@ -1,15 +1,16 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type InlineXHTMLContent struct {
|
||||
XMLName xml.Name `xml:"content"`
|
||||
*CommonAttributes
|
||||
XHTMLDiv *XHTMLDiv
|
||||
Type string `xml:"type,attr"`
|
||||
XHTMLDiv string `xml:"xhtmldiv"`
|
||||
}
|
||||
|
||||
// newInlineXHTMLContent creates a new InlineXHTMLContent. It returns a
|
||||
@ -19,11 +20,12 @@ func newInlineXHTMLContent(mediaType string, content any) (*InlineXHTMLContent,
|
||||
return nil, fmt.Errorf("media type %v incompatible with inline xhtml content", mediaType)
|
||||
}
|
||||
|
||||
if reflect.TypeOf(content).Kind() != reflect.String {
|
||||
xhtmlDiv, ok := content.(*XHTMLDiv)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("content type %T incompatible with inline xhtml content", content)
|
||||
}
|
||||
|
||||
return &InlineXHTMLContent{Type: mediaType, XHTMLDiv: content.(string)}, nil
|
||||
return &InlineXHTMLContent{Type: mediaType, XHTMLDiv: xhtmlDiv}, nil
|
||||
}
|
||||
|
||||
// isContent checks whether the InlineXHTMLContent is a Content. It returns a
|
||||
@ -44,8 +46,8 @@ func (i *InlineXHTMLContent) Check() error {
|
||||
return errors.New("type attribute of inline xhtml content must be xhtml")
|
||||
}
|
||||
|
||||
if i.XHTMLDiv == "" {
|
||||
return errors.New("xhtmlDiv element of inline xhtml content empty")
|
||||
if err := i.XHTMLDiv.Check(); err != nil {
|
||||
return fmt.Errorf("xhtml div element %v of inline xhtml content %v: %v", i.XHTMLDiv, i, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
22
link.go
22
link.go
@ -1,15 +1,16 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
XMLName xml.Name `xml:"link"`
|
||||
*CommonAttributes
|
||||
Title string `xml:"title,attr,omitempty"`
|
||||
Content Content `xml:"content"` // undefinedContent in RFC4287
|
||||
Href IRI `xml:"href,attr"`
|
||||
Rel string `xml:"rel,attr,omitempty"`
|
||||
Type MediaType `xml:"type,attr,omitempty"`
|
||||
@ -17,14 +18,9 @@ type Link struct {
|
||||
Length uint `xml:"length,attr,omitempty"`
|
||||
}
|
||||
|
||||
// NewLink creates a new Link. It returns a *Link and an error.
|
||||
func NewLink(href string) (*Link, error) {
|
||||
content, err := NewContent(InlineText, "", "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating content element: %v", err)
|
||||
}
|
||||
|
||||
return &Link{Href: IRI(href), Content: content}, nil
|
||||
// NewLink creates a new Link. It returns a *Link.
|
||||
func NewLink(href string) *Link {
|
||||
return &Link{Href: IRI(href)}
|
||||
}
|
||||
|
||||
// Check checks the Link for incompatibilities with RFC4287. It returns an
|
||||
@ -56,14 +52,6 @@ func (l *Link) Check() error {
|
||||
}
|
||||
}
|
||||
|
||||
if l.Content == nil {
|
||||
return fmt.Errorf("no content element of link %v", l.Href)
|
||||
} else {
|
||||
if err := l.Content.Check(); err != nil {
|
||||
return fmt.Errorf("content element of link %v: %v", l.Href, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
14
logo.go
14
logo.go
@ -1,20 +1,24 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Logo struct {
|
||||
XMLName xml.Name `xml:"logo"`
|
||||
*CommonAttributes
|
||||
URI IRI `xml:"uri"`
|
||||
URI IRI `xml:",chardata"`
|
||||
}
|
||||
|
||||
// NewLogo creates a new Logo. It returns a *Logo.
|
||||
func NewLogo() *Logo {
|
||||
return &Logo{URI: IRI(fmt.Sprint("urn:uuid:", uuid.New()))}
|
||||
func NewLogo(uri IRI) (*Logo, error) {
|
||||
if !isValidIRI(uri) {
|
||||
return nil, fmt.Errorf("uri %v not correctly formatted", uri)
|
||||
}
|
||||
|
||||
return &Logo{URI: uri}, nil
|
||||
}
|
||||
|
||||
// Check checks the Logo for incompatibilities with RFC4287. It returns an
|
||||
|
@ -1,13 +1,14 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type OutOfLineContent struct {
|
||||
XMLName xml.Name `xml:"content"`
|
||||
*CommonAttributes
|
||||
Type MediaType `xml:"type,attr,omitempty"`
|
||||
SRC IRI `xml:"src,attr"`
|
||||
@ -20,15 +21,16 @@ func newOutOfLineContent(mediaType string, content any) (*OutOfLineContent, erro
|
||||
return nil, fmt.Errorf("media type %v incompatible with out of line content", mediaType)
|
||||
}
|
||||
|
||||
if reflect.TypeOf(content).Kind() != reflect.String {
|
||||
iri, ok := content.(IRI)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("content type %T incompatible with out of line content", content)
|
||||
}
|
||||
|
||||
if !isValidIRI(content.(IRI)) {
|
||||
if !isValidIRI(iri) {
|
||||
return nil, errors.New("content not a valid uri")
|
||||
}
|
||||
|
||||
return &OutOfLineContent{Type: MediaType(mediaType), SRC: content.(IRI)}, nil
|
||||
return &OutOfLineContent{Type: MediaType(mediaType), SRC: iri}, nil
|
||||
}
|
||||
|
||||
// isContent checks whether the OutOfLineContent is a Content. It returns a
|
||||
|
18
source.go
18
source.go
@ -1,17 +1,21 @@
|
||||
package atom
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Source struct {
|
||||
XMLName xml.Name `xml:"source"`
|
||||
*CommonAttributes
|
||||
Authors []*Person `xml:"author,omitempty"`
|
||||
Categories []*Category `xml:"category,omitempty"`
|
||||
Categories []*Category `xml:",omitempty"`
|
||||
Contributors []*Person `xml:"contributor,omitempty"`
|
||||
Generator *Generator `xml:"generator,omitempty"`
|
||||
Icon *Icon `xml:"icon,omitempty"`
|
||||
ID *ID `xml:"id,omitempty"`
|
||||
Links []*Link `xml:"link,omitempty"`
|
||||
Logo *Logo `xml:"logo,omitempty"`
|
||||
Generator *Generator `xml:",omitempty"`
|
||||
Icon *Icon `xml:",omitempty"`
|
||||
ID *ID `xml:",omitempty"`
|
||||
Links []*Link `xml:",omitempty"`
|
||||
Logo *Logo `xml:",omitempty"`
|
||||
Rights Text `xml:"rights,omitempty"`
|
||||
Subtitle Text `xml:"subtitle,omitempty"`
|
||||
Title Text `xml:"title,omitempty"`
|
||||
|
2
text.go
2
text.go
@ -20,7 +20,7 @@ func NewText(textType, content string) (Text, error) {
|
||||
case "xhtml":
|
||||
return &XHTMLText{
|
||||
Type: textType,
|
||||
XHTMLDiv: XHTMLDiv{
|
||||
XHTMLDiv: &XHTMLDiv{
|
||||
XMLNS: "http://www.w3.org/1999/xhtml",
|
||||
Content: content,
|
||||
},
|
||||
|
30
xhtmlDiv.go
Normal file
30
xhtmlDiv.go
Normal file
@ -0,0 +1,30 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type XHTMLDiv struct {
|
||||
XMLName xml.Name `xml:"div"`
|
||||
XMLNS string `xml:"xmlns,attr"`
|
||||
Content string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
// NewXHTMLDiv creates a new XHTMLDiv. It returns a *XHTMLDiv.
|
||||
func NewXHTMLDiv(content string) *XHTMLDiv {
|
||||
return &XHTMLDiv{
|
||||
XMLNS: "http://www.w3.org/1999/xhtml",
|
||||
Content: content,
|
||||
}
|
||||
}
|
||||
|
||||
// Check checks the XHTMLDiv for incompatibilities with RFC4287. It returns an
|
||||
// error.
|
||||
func (x *XHTMLDiv) Check() error {
|
||||
if x.XMLNS != "http://www.w3.org/1999/xhtml" {
|
||||
return errors.New("xmlns attribute of xhtml text must be http://www.w3.org/1999/xhtml")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
14
xhtmlText.go
14
xhtmlText.go
@ -1,20 +1,14 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type XHTMLDiv struct {
|
||||
XMLName xml.Name `xml:"div"`
|
||||
XMLNS string `xml:"xmlns,attr"`
|
||||
Content string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type XHTMLText struct {
|
||||
*CommonAttributes
|
||||
XHTMLDiv *XHTMLDiv
|
||||
Type string `xml:"type,attr"` // Must be xhtml
|
||||
XHTMLDiv XHTMLDiv
|
||||
}
|
||||
|
||||
// isText checks whether the XHTMLText is a Text. It returns a bool.
|
||||
@ -27,8 +21,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 err := x.XHTMLDiv.Check(); err != nil {
|
||||
return fmt.Errorf("xhtml div element %v of xhtml text %v: %v", x.XHTMLDiv, x, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user