2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
2024-10-15 21:14:30 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
InlineText = iota
|
|
|
|
InlineXHTML
|
|
|
|
InlineOther
|
|
|
|
OutOfLine
|
|
|
|
)
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
type Content interface {
|
2024-10-15 19:32:14 +02:00
|
|
|
isContent() bool
|
|
|
|
hasSRC() bool
|
|
|
|
getType() string
|
2024-10-13 17:19:40 +02:00
|
|
|
Check() error
|
|
|
|
}
|
2024-10-15 21:14:30 +02:00
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// NewContent creates a new Content. It returns a Content and an error.
|
2024-10-15 21:14:30 +02:00
|
|
|
func NewContent(contentType int, mediaType string, content any) (Content, error) {
|
|
|
|
switch contentType {
|
|
|
|
case 0:
|
|
|
|
return newInlineTextContent(mediaType, content)
|
|
|
|
case 1:
|
|
|
|
return newInlineXHTMLContent(mediaType, content)
|
|
|
|
case 2:
|
|
|
|
return newInlineOtherContent(mediaType, content)
|
|
|
|
case 3:
|
|
|
|
return newOutOfLineContent(mediaType, content)
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("%v is not a valid text type", contentType)
|
|
|
|
}
|
|
|
|
}
|