markdown.go 702 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package misc
  5. import (
  6. api "github.com/gogs/go-gogs-client"
  7. "gogs.io/gogs/internal/context"
  8. "gogs.io/gogs/internal/markup"
  9. )
  10. func Markdown(c *context.APIContext, form api.MarkdownOption) {
  11. if len(form.Text) == 0 {
  12. _, _ = c.Write([]byte(""))
  13. return
  14. }
  15. _, _ = c.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
  16. }
  17. func MarkdownRaw(c *context.APIContext) {
  18. body, err := c.Req.Body().Bytes()
  19. if err != nil {
  20. c.Error(err, "read body")
  21. return
  22. }
  23. _, _ = c.Write(markup.SanitizeBytes(markup.RawMarkdown(body, "")))
  24. }