diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-05 13:08:01 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-05 13:08:01 -0400 |
commit | c1eb4d894a092aed1b87ddf5f80ee824fd56789d (patch) | |
tree | b58beee7c762cbbb1cec524c16471788820609b6 /routers/api | |
parent | 5f653898f3b39669ce9dbf0ee2263c391695019d (diff) | |
download | gitea-c1eb4d894a092aed1b87ddf5f80ee824fd56789d.tar.gz gitea-c1eb4d894a092aed1b87ddf5f80ee824fd56789d.zip |
Clean api code
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/miscellaneous.go | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/routers/api/v1/miscellaneous.go b/routers/api/v1/miscellaneous.go index babdfce9b2..30751efcca 100644 --- a/routers/api/v1/miscellaneous.go +++ b/routers/api/v1/miscellaneous.go @@ -5,14 +5,38 @@ package v1 import ( + "io/ioutil" + "strings" + + "github.com/gogits/gogs/modules/auth/apiv1" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) -func Markdown(ctx *middleware.Context) { - content := ctx.Query("content") - ctx.Render.JSON(200, map[string]interface{}{ - "ok": true, - "content": string(base.RenderMarkdown([]byte(content), ctx.Query("repoLink"))), - }) +const DOC_URL = "http://gogs.io/docs" + +// Render an arbitrary Markdown document. +func Markdown(ctx *middleware.Context, form apiv1.MarkdownForm) { + if ctx.HasApiError() { + ctx.JSON(422, base.ApiJsonErr{ctx.GetErrMsg(), DOC_URL}) + return + } + + switch form.Mode { + case "gfm": + ctx.Write(base.RenderMarkdown([]byte(form.Text), + base.AppUrl+strings.TrimPrefix(form.Context, "/"))) + default: + ctx.Write(base.RenderRawMarkdown([]byte(form.Text), "")) + } +} + +// Render a Markdown document in raw mode. +func MarkdownRaw(ctx *middleware.Context) { + body, err := ioutil.ReadAll(ctx.Req.Body) + if err != nil { + ctx.JSON(422, base.ApiJsonErr{err.Error(), DOC_URL}) + return + } + ctx.Write(base.RenderRawMarkdown(body, "")) } |