33 lines
689 B
Go
33 lines
689 B
Go
package article
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
var ErrUnsupportedBodyFormat = errors.New("unsupported body format")
|
|
|
|
type BodyFormat string
|
|
|
|
const (
|
|
BodyFormatMarkdown BodyFormat = "markdown"
|
|
BodyFormatHTML BodyFormat = "html"
|
|
BodyFormatJSON BodyFormat = "json"
|
|
)
|
|
|
|
func ParseBodyFormat(value string) (BodyFormat, error) {
|
|
switch strings.ToLower(value) {
|
|
case "", string(BodyFormatMarkdown):
|
|
return BodyFormatMarkdown, nil
|
|
case string(BodyFormatHTML):
|
|
return BodyFormatHTML, nil
|
|
case string(BodyFormatJSON):
|
|
return BodyFormatJSON, nil
|
|
}
|
|
return "", ErrUnsupportedBodyFormat
|
|
}
|
|
|
|
type BodyRenderer interface {
|
|
Render(html string, format BodyFormat) (string, error)
|
|
}
|