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.
|
|
|
|
|
|
2015-12-04 17:16:42 -05:00
|
|
|
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"
|
2015-12-04 17:16:42 -05:00
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
"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) {
|
2022-03-06 16:33:45 +08:00
|
|
|
if form.Text == "" {
|
2020-01-27 00:18:46 +08:00
|
|
|
_, _ = c.Write([]byte(""))
|
2014-12-10 16:37:54 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-29 02:41:31 +08:00
|
|
|
_, _ = 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 {
|
2020-03-16 01:22:27 +08:00
|
|
|
c.Error(err, "read body")
|
2014-05-05 13:08:01 -04:00
|
|
|
return
|
|
|
|
|
}
|
2020-01-27 00:18:46 +08:00
|
|
|
_, _ = c.Write(markup.SanitizeBytes(markup.RawMarkdown(body, "")))
|
2014-03-29 21:16:06 +08:00
|
|
|
}
|