mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-19 00:10:15 +00:00
Refactor renders (#15175)
* Refactor renders * Some performance optimization * Fix comment * Transform reader * Fix csv test * Fix test * Fix tests * Improve optimaziation * Fix test * Fix test * Detect file encoding with reader * Improve optimaziation * reduce memory usage * improve code * fix build * Fix test * Fix for go1.15 * Fix render * Fix comment * Fix lint * Fix test * Don't use NormalEOF when unnecessary * revert change on util.go * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * rename function * Take NormalEOF back Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
c9cc6698d2
commit
9d99f6ab19
41 changed files with 1027 additions and 627 deletions
|
@ -5,11 +5,11 @@
|
|||
package misc
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
@ -55,7 +55,6 @@ func Markdown(ctx *context.APIContext) {
|
|||
case "comment":
|
||||
fallthrough
|
||||
case "gfm":
|
||||
md := []byte(form.Text)
|
||||
urlPrefix := form.Context
|
||||
meta := map[string]string{}
|
||||
if !strings.HasPrefix(setting.AppSubURL+"/", urlPrefix) {
|
||||
|
@ -77,22 +76,19 @@ func Markdown(ctx *context.APIContext) {
|
|||
if form.Mode == "gfm" {
|
||||
meta["mode"] = "document"
|
||||
}
|
||||
if form.Wiki {
|
||||
_, err := ctx.Write([]byte(markdown.RenderWiki(md, urlPrefix, meta)))
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
_, err := ctx.Write(markdown.Render(md, urlPrefix, meta))
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := markdown.Render(&markup.RenderContext{
|
||||
URLPrefix: urlPrefix,
|
||||
Metas: meta,
|
||||
IsWiki: form.Wiki,
|
||||
}, strings.NewReader(form.Text), ctx.Resp); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
default:
|
||||
_, err := ctx.Write(markdown.RenderRaw([]byte(form.Text), "", false))
|
||||
if err != nil {
|
||||
if err := markdown.RenderRaw(&markup.RenderContext{
|
||||
URLPrefix: form.Context,
|
||||
}, strings.NewReader(form.Text), ctx.Resp); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
@ -120,14 +116,8 @@ func MarkdownRaw(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/MarkdownRender"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
body, err := ioutil.ReadAll(ctx.Req.Body)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusUnprocessableEntity, "", err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(markdown.RenderRaw(body, "", false))
|
||||
if err != nil {
|
||||
defer ctx.Req.Body.Close()
|
||||
if err := markdown.RenderRaw(&markup.RenderContext{}, ctx.Req.Body, ctx.Resp); err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue