1
0

markdown.go 553 B

12345678910111213141516171819202122232425262728
  1. package misc
  2. import (
  3. "io"
  4. api "github.com/gogs/go-gogs-client"
  5. "gogs.io/gogs/internal/context"
  6. "gogs.io/gogs/internal/markup"
  7. )
  8. func Markdown(c *context.APIContext, form api.MarkdownOption) {
  9. if form.Text == "" {
  10. _, _ = c.Write([]byte(""))
  11. return
  12. }
  13. _, _ = c.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
  14. }
  15. func MarkdownRaw(c *context.APIContext) {
  16. body, err := io.ReadAll(c.Req.Request.Body)
  17. if err != nil {
  18. c.Error(err, "read body")
  19. return
  20. }
  21. _, _ = c.Write(markup.SanitizeBytes(markup.RawMarkdown(body, "")))
  22. }