feat: articles format option with markdown new default
This commit is contained in:
1 parent
68401d66e0
commit
7e9bd9ba30
61 files changed
+2269
-243
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package markdown
|
||||
|
||||
import (
|
||||
domain "RenewCMS/internal/domain/article"
|
||||
)
|
||||
|
||||
type Converter struct{}
|
||||
|
||||
var _ domain.BodyRenderer = &Converter{}
|
||||
|
||||
func NewConverter() *Converter {
|
||||
return &Converter{}
|
||||
}
|
||||
|
||||
func (c *Converter) Render(html string, format domain.BodyFormat) (string, error) {
|
||||
switch format {
|
||||
case domain.BodyFormatHTML:
|
||||
return html, nil
|
||||
case domain.BodyFormatMarkdown:
|
||||
blocks, err := parseBlocks(html)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return renderMarkdown(blocks), nil
|
||||
case domain.BodyFormatJSON:
|
||||
blocks, err := parseBlocks(html)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return renderJSON(blocks)
|
||||
}
|
||||
return "", domain.ErrUnsupportedBodyFormat
|
||||
}
|
||||
Reference in new issue
Block a user