You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  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/gogits/go-gogs-client"
  7. "github.com/gogits/gogs/modules/markdown"
  8. "github.com/gogits/gogs/modules/middleware"
  9. )
  10. // https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
  11. func Markdown(ctx *middleware.Context, form api.MarkdownOption) {
  12. if ctx.HasApiError() {
  13. ctx.APIError(422, "", ctx.GetErrMsg())
  14. return
  15. }
  16. if len(form.Text) == 0 {
  17. ctx.Write([]byte(""))
  18. return
  19. }
  20. switch form.Mode {
  21. case "gfm":
  22. ctx.Write(markdown.Render([]byte(form.Text), form.Context, nil))
  23. default:
  24. ctx.Write(markdown.RenderRaw([]byte(form.Text), ""))
  25. }
  26. }
  27. // https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
  28. func MarkdownRaw(ctx *middleware.Context) {
  29. body, err := ctx.Req.Body().Bytes()
  30. if err != nil {
  31. ctx.APIError(422, "", err)
  32. return
  33. }
  34. ctx.Write(markdown.RenderRaw(body, ""))
  35. }