summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/misc
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-12-04 17:16:42 -0500
committerUnknwon <u@gogs.io>2015-12-04 17:16:42 -0500
commit56dd430a10bf5281caf648344e4660fbdc5d4dee (patch)
tree9493b1a9f77321525d62ce1ccefc4dd792391832 /routers/api/v1/misc
parente0bae9547af03e5e7c0201faaa9568d6a1cc9e1f (diff)
downloadgitea-56dd430a10bf5281caf648344e4660fbdc5d4dee.tar.gz
gitea-56dd430a10bf5281caf648344e4660fbdc5d4dee.zip
refactor API routes and some work for #976
Diffstat (limited to 'routers/api/v1/misc')
-rw-r--r--routers/api/v1/misc/markdown.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go
new file mode 100644
index 0000000000..49979ef767
--- /dev/null
+++ b/routers/api/v1/misc/markdown.go
@@ -0,0 +1,42 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package misc
+
+import (
+ api "github.com/gogits/go-gogs-client"
+
+ "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/middleware"
+)
+
+// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
+func Markdown(ctx *middleware.Context, form api.MarkdownOption) {
+ if ctx.HasApiError() {
+ ctx.APIError(422, "", ctx.GetErrMsg())
+ return
+ }
+
+ if len(form.Text) == 0 {
+ ctx.Write([]byte(""))
+ return
+ }
+
+ switch form.Mode {
+ case "gfm":
+ ctx.Write(base.RenderMarkdown([]byte(form.Text), form.Context))
+ default:
+ ctx.Write(base.RenderRawMarkdown([]byte(form.Text), ""))
+ }
+}
+
+// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
+func MarkdownRaw(ctx *middleware.Context) {
+ body, err := ctx.Req.Body().Bytes()
+ if err != nil {
+ ctx.APIError(422, "", err)
+ return
+ }
+ ctx.Write(base.RenderRawMarkdown(body, ""))
+}