Files
Gogs/internal/route/api/v1/misc/markdown.go

31 lines
702 B
Go
Raw Normal View History

2014-03-29 21:16:06 +08:00
// 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
2014-03-29 21:16:06 +08:00
2014-03-29 10:01:52 -04:00
import (
2018-05-27 08:53:48 +08:00
api "github.com/gogs/go-gogs-client"
"gogs.io/gogs/internal/context"
"gogs.io/gogs/internal/markup"
2014-03-29 10:01:52 -04:00
)
2014-03-29 21:16:06 +08:00
2017-06-03 07:26:09 -04:00
func Markdown(c *context.APIContext, form api.MarkdownOption) {
2014-12-10 16:37:54 -05:00
if len(form.Text) == 0 {
_, _ = c.Write([]byte(""))
2014-12-10 16:37:54 -05:00
return
}
_, _ = c.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
2014-05-05 13:08:01 -04:00
}
2017-06-03 07:26:09 -04:00
func MarkdownRaw(c *context.APIContext) {
body, err := c.Req.Body().Bytes()
2014-05-05 13:08:01 -04:00
if err != nil {
c.Error(err, "read body")
2014-05-05 13:08:01 -04:00
return
}
_, _ = c.Write(markup.SanitizeBytes(markup.RawMarkdown(body, "")))
2014-03-29 21:16:06 +08:00
}