markdown.go 536 B

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