2014-03-29 18:46:06 +05:30
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2014-03-29 18:46:06 +05:30
|
|
|
|
2015-12-05 03:46:42 +05:30
|
|
|
package misc
|
2014-03-29 18:46:06 +05:30
|
|
|
|
2014-03-29 19:31:52 +05:30
|
|
|
import (
|
2019-06-13 01:11:28 +05:30
|
|
|
"net/http"
|
2019-04-12 11:23:34 +05:30
|
|
|
|
2021-04-20 03:55:08 +05:30
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2017-09-21 10:50:14 +05:30
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2019-08-23 22:10:30 +05:30
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2021-01-26 21:06:53 +05:30
|
|
|
"code.gitea.io/gitea/modules/web"
|
2023-03-24 11:42:23 +05:30
|
|
|
"code.gitea.io/gitea/routers/common"
|
2024-02-27 12:42:22 +05:30
|
|
|
"code.gitea.io/gitea/services/context"
|
2014-03-29 19:31:52 +05:30
|
|
|
)
|
2014-03-29 18:46:06 +05:30
|
|
|
|
2023-03-24 11:42:23 +05:30
|
|
|
// Markup render markup document to HTML
|
|
|
|
func Markup(ctx *context.APIContext) {
|
|
|
|
// swagger:operation POST /markup miscellaneous renderMarkup
|
|
|
|
// ---
|
|
|
|
// summary: Render a markup document as HTML
|
|
|
|
// parameters:
|
|
|
|
// - name: body
|
|
|
|
// in: body
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/definitions/MarkupOption"
|
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// produces:
|
|
|
|
// - text/html
|
|
|
|
// responses:
|
|
|
|
// "200":
|
|
|
|
// "$ref": "#/responses/MarkupRender"
|
|
|
|
// "422":
|
|
|
|
// "$ref": "#/responses/validationError"
|
|
|
|
|
|
|
|
form := web.GetForm(ctx).(*api.MarkupOption)
|
|
|
|
|
|
|
|
if ctx.HasAPIError() {
|
|
|
|
ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-21 07:20:53 +05:30
|
|
|
common.RenderMarkup(ctx.Base, ctx.Repo, form.Mode, form.Text, form.Context, form.FilePath, form.Wiki)
|
2023-03-24 11:42:23 +05:30
|
|
|
}
|
|
|
|
|
2016-11-24 12:34:31 +05:30
|
|
|
// Markdown render markdown document to HTML
|
2021-01-26 21:06:53 +05:30
|
|
|
func Markdown(ctx *context.APIContext) {
|
2017-11-13 12:32:25 +05:30
|
|
|
// swagger:operation POST /markdown miscellaneous renderMarkdown
|
|
|
|
// ---
|
|
|
|
// summary: Render a markdown document as HTML
|
|
|
|
// parameters:
|
|
|
|
// - name: body
|
|
|
|
// in: body
|
|
|
|
// schema:
|
|
|
|
// "$ref": "#/definitions/MarkdownOption"
|
|
|
|
// consumes:
|
|
|
|
// - application/json
|
|
|
|
// produces:
|
2017-05-02 19:05:59 +05:30
|
|
|
// - text/html
|
2017-11-13 12:32:25 +05:30
|
|
|
// responses:
|
|
|
|
// "200":
|
|
|
|
// "$ref": "#/responses/MarkdownRender"
|
|
|
|
// "422":
|
|
|
|
// "$ref": "#/responses/validationError"
|
2019-12-20 22:37:12 +05:30
|
|
|
|
2021-01-26 21:06:53 +05:30
|
|
|
form := web.GetForm(ctx).(*api.MarkdownOption)
|
|
|
|
|
2016-11-25 12:21:01 +05:30
|
|
|
if ctx.HasAPIError() {
|
2019-12-20 22:37:12 +05:30
|
|
|
ctx.Error(http.StatusUnprocessableEntity, "", ctx.GetErrMsg())
|
2014-05-05 22:38:01 +05:30
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-24 11:42:23 +05:30
|
|
|
mode := "markdown"
|
|
|
|
if form.Mode == "comment" || form.Mode == "gfm" {
|
|
|
|
mode = form.Mode
|
2014-12-11 03:07:54 +05:30
|
|
|
}
|
|
|
|
|
2023-05-21 07:20:53 +05:30
|
|
|
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, "", form.Wiki)
|
2014-05-05 22:38:01 +05:30
|
|
|
}
|
|
|
|
|
2016-11-24 12:34:31 +05:30
|
|
|
// MarkdownRaw render raw markdown HTML
|
2016-03-14 04:19:16 +05:30
|
|
|
func MarkdownRaw(ctx *context.APIContext) {
|
2017-11-13 12:32:25 +05:30
|
|
|
// swagger:operation POST /markdown/raw miscellaneous renderMarkdownRaw
|
|
|
|
// ---
|
|
|
|
// summary: Render raw markdown as HTML
|
|
|
|
// parameters:
|
2018-06-12 20:29:22 +05:30
|
|
|
// - name: body
|
|
|
|
// in: body
|
|
|
|
// description: Request body to render
|
|
|
|
// required: true
|
|
|
|
// schema:
|
|
|
|
// type: string
|
2017-11-13 12:32:25 +05:30
|
|
|
// consumes:
|
2017-05-02 19:05:59 +05:30
|
|
|
// - text/plain
|
2017-11-13 12:32:25 +05:30
|
|
|
// produces:
|
2017-05-02 19:05:59 +05:30
|
|
|
// - text/html
|
2017-11-13 12:32:25 +05:30
|
|
|
// responses:
|
|
|
|
// "200":
|
|
|
|
// "$ref": "#/responses/MarkdownRender"
|
|
|
|
// "422":
|
|
|
|
// "$ref": "#/responses/validationError"
|
2021-04-20 03:55:08 +05:30
|
|
|
defer ctx.Req.Body.Close()
|
2022-01-20 04:56:57 +05:30
|
|
|
if err := markdown.RenderRaw(&markup.RenderContext{
|
|
|
|
Ctx: ctx,
|
|
|
|
}, ctx.Req.Body, ctx.Resp); err != nil {
|
2019-12-20 22:37:12 +05:30
|
|
|
ctx.InternalServerError(err)
|
2019-06-13 01:11:28 +05:30
|
|
|
return
|
|
|
|
}
|
2014-03-29 18:46:06 +05:30
|
|
|
}
|