markdown.go 630 B

123456789101112131415161718192021222324252627282930
  1. package misc
  2. import (
  3. "gogs.io/gogs/internal/context"
  4. "gogs.io/gogs/internal/markup"
  5. )
  6. // MarkdownRequest represents the request body for rendering markdown.
  7. type MarkdownRequest struct {
  8. Text string
  9. Context string
  10. }
  11. func Markdown(c *context.APIContext, form MarkdownRequest) {
  12. if form.Text == "" {
  13. _, _ = c.Write([]byte(""))
  14. return
  15. }
  16. _, _ = c.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
  17. }
  18. func MarkdownRaw(c *context.APIContext) {
  19. body, err := c.Req.Body().Bytes()
  20. if err != nil {
  21. c.Error(err, "read body")
  22. return
  23. }
  24. _, _ = c.Write(markup.SanitizeBytes(markup.RawMarkdown(body, "")))
  25. }