From 15b74c2675835ed03838dedebddc7868ead42f67 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 15 Oct 2024 20:53:01 +0200 Subject: [PATCH] Add newInlineXHTMLContent --- inlineXHTMLContent.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/inlineXHTMLContent.go b/inlineXHTMLContent.go index 0d0b33e..41030be 100644 --- a/inlineXHTMLContent.go +++ b/inlineXHTMLContent.go @@ -1,6 +1,10 @@ package atomfeed -import "errors" +import ( + "errors" + "fmt" + "reflect" +) type InlineXHTMLContent struct { *CommonAttributes @@ -8,6 +12,18 @@ type InlineXHTMLContent struct { XHTMLDiv string `xml:"xhtmldiv"` } +func newInlineXHTMLContent(mediaType string, content any) (*InlineXHTMLContent, error) { + if mediaType != "xhtml" { + return nil, fmt.Errorf("media type %v incompatible with inline xhtml content", mediaType) + } + + if reflect.TypeOf(content).Kind() != reflect.String { + return nil, fmt.Errorf("content type %T incompatible with inline xhtml content", content) + } + + return &InlineXHTMLContent{Type: mediaType, XHTMLDiv: content.(string)}, nil +} + func (i *InlineXHTMLContent) isContent() bool { return true } func (i *InlineXHTMLContent) hasSRC() bool { return false }