Simplify inline text content
This commit is contained in:
parent
86785be588
commit
4b97bf7fdc
@ -9,7 +9,7 @@ import (
|
||||
type InlineTextContent struct {
|
||||
*CommonAttributes
|
||||
Type string `xml:"type,attr,omitempty"` // Must be text or html
|
||||
Texts []string `xml:",chardata"`
|
||||
Text string `xml:",chardata"`
|
||||
}
|
||||
|
||||
// newInlineTextContent creates a new InlineTextContent. It returns a
|
||||
@ -19,23 +19,11 @@ func newInlineTextContent(mediaType string, content any) (*InlineTextContent, er
|
||||
return nil, fmt.Errorf("media type %v incompatible with inline text content", mediaType)
|
||||
}
|
||||
|
||||
texts := make([]string, 0)
|
||||
|
||||
t := reflect.TypeOf(content)
|
||||
switch t.Kind() {
|
||||
case reflect.Slice:
|
||||
if t.Elem().Kind() == reflect.String {
|
||||
for _, t := range content.([]string) {
|
||||
texts = append(texts, t)
|
||||
}
|
||||
}
|
||||
case reflect.String:
|
||||
texts = append(texts, content.(string))
|
||||
default:
|
||||
if reflect.TypeOf(content).Kind() != reflect.String {
|
||||
return nil, fmt.Errorf("content type %T incompatible with inline text content", content)
|
||||
}
|
||||
|
||||
return &InlineTextContent{Type: mediaType, Texts: texts}, nil
|
||||
return &InlineTextContent{Type: mediaType, Text: content.(string)}, nil
|
||||
}
|
||||
|
||||
// isContent checks whether the InlineTextContent is a Content. It returns a
|
||||
|
Loading…
x
Reference in New Issue
Block a user