markdown.go 892 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 Gitote. All rights reserved.
  3. //
  4. // This source code is licensed under the MIT license found in the
  5. // LICENSE file in the root directory of this source tree.
  6. package misc
  7. import (
  8. "gitote/gitote/pkg/context"
  9. "gitote/gitote/pkg/markup"
  10. api "gitlab.com/gitote/go-gitote-client"
  11. )
  12. func Markdown(c *context.APIContext, form api.MarkdownOption) {
  13. if c.HasApiError() {
  14. c.Error(422, "", c.GetErrMsg())
  15. return
  16. }
  17. if len(form.Text) == 0 {
  18. c.Write([]byte(""))
  19. return
  20. }
  21. switch form.Mode {
  22. case "gfm":
  23. c.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
  24. default:
  25. c.Write(markup.RawMarkdown([]byte(form.Text), ""))
  26. }
  27. }
  28. func MarkdownRaw(c *context.APIContext) {
  29. body, err := c.Req.Body().Bytes()
  30. if err != nil {
  31. c.Error(422, "", err)
  32. return
  33. }
  34. c.Write(markup.RawMarkdown(body, ""))
  35. }