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

10 years ago
10 years ago
10 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 v1
  5. import (
  6. "strings"
  7. "github.com/gogits/gogs/modules/auth/apiv1"
  8. "github.com/gogits/gogs/modules/base"
  9. "github.com/gogits/gogs/modules/middleware"
  10. "github.com/gogits/gogs/modules/setting"
  11. )
  12. const DOC_URL = "http://gogs.io/docs"
  13. // Render an arbitrary Markdown document.
  14. func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) {
  15. if ctx.HasApiError() {
  16. ctx.JSON(422, base.ApiJsonErr{ctx.GetErrMsg(), DOC_URL})
  17. return
  18. }
  19. switch form.Mode {
  20. case "gfm":
  21. ctx.Write(base.RenderMarkdown([]byte(form.Text),
  22. setting.AppUrl+strings.TrimPrefix(form.Context, "/")))
  23. default:
  24. ctx.Write(base.RenderRawMarkdown([]byte(form.Text), ""))
  25. }
  26. }
  27. // 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.JSON(422, base.ApiJsonErr{err.Error(), DOC_URL})
  32. return
  33. }
  34. ctx.Write(base.RenderRawMarkdown(body, ""))
  35. }