1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-28 05:08:37 +00:00

Fix and refactor markdown rendering (#32522)

This commit is contained in:
wxiaoguang
2024-11-16 16:41:44 +08:00
committed by GitHub
parent e546480d0a
commit 5eebe1dc5f
27 changed files with 289 additions and 278 deletions

View File

@@ -47,11 +47,12 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, urlPa
switch mode {
case "gfm": // legacy mode, do nothing
case "comment":
renderCtx.ContentMode = markup.RenderContentAsComment
renderCtx.Metas = map[string]string{"markdownLineBreakStyle": "comment"}
case "wiki":
renderCtx.ContentMode = markup.RenderContentAsWiki
renderCtx.Metas = map[string]string{"markdownLineBreakStyle": "document", "markupContentMode": "wiki"}
case "file":
// render the repo file content by its extension
renderCtx.Metas = map[string]string{"markdownLineBreakStyle": "document"}
renderCtx.MarkupType = ""
renderCtx.RelativePath = filePath
renderCtx.InStandalonePage = true
@@ -74,10 +75,12 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, urlPa
if repo != nil && repo.Repository != nil {
renderCtx.Repo = repo.Repository
if renderCtx.ContentMode == markup.RenderContentAsComment {
renderCtx.Metas = repo.Repository.ComposeMetas(ctx)
} else {
if mode == "file" {
renderCtx.Metas = repo.Repository.ComposeDocumentMetas(ctx)
} else if mode == "wiki" {
renderCtx.Metas = repo.Repository.ComposeWikiMetas(ctx)
} else if mode == "comment" {
renderCtx.Metas = repo.Repository.ComposeMetas(ctx)
}
}
if err := markup.Render(renderCtx, strings.NewReader(text), ctx.Resp); err != nil {

View File

@@ -56,7 +56,7 @@ func renderMarkdown(ctx *context.Context, act *activities_model.Action, content
Links: markup.Links{
Base: act.GetRepoLink(ctx),
},
Metas: map[string]string{
Metas: map[string]string{ // FIXME: not right here, it should use issue to compose the metas
"user": act.GetRepoUserName(ctx),
"repo": act.GetRepoName(ctx),
},

View File

@@ -46,9 +46,7 @@ func showUserFeed(ctx *context.Context, formatType string) {
Links: markup.Links{
Base: ctx.ContextUser.HTMLURL(),
},
Metas: map[string]string{
"user": ctx.ContextUser.GetDisplayName(),
},
Metas: markup.ComposeSimpleDocumentMetas(),
}, ctx.ContextUser.Description)
if err != nil {
ctx.ServerError("RenderString", err)

View File

@@ -189,7 +189,7 @@ func prepareOrgProfileReadme(ctx *context.Context, viewRepositories bool) bool {
Base: profileDbRepo.Link(),
BranchPath: path.Join("branch", util.PathEscapeSegments(profileDbRepo.DefaultBranch)),
},
Metas: map[string]string{"mode": "document"},
Metas: markup.ComposeSimpleDocumentMetas(),
}, bytes); err != nil {
log.Error("failed to RenderString: %v", err)
} else {

View File

@@ -289,9 +289,8 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
}
rctx := &markup.RenderContext{
Ctx: ctx,
ContentMode: markup.RenderContentAsWiki,
Metas: ctx.Repo.Repository.ComposeDocumentMetas(ctx),
Ctx: ctx,
Metas: ctx.Repo.Repository.ComposeWikiMetas(ctx),
Links: markup.Links{
Base: ctx.Repo.RepoLink,
},

View File

@@ -50,7 +50,7 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
ctx.Data["OpenIDs"] = openIDs
if len(ctx.ContextUser.Description) != 0 {
content, err := markdown.RenderString(&markup.RenderContext{
Metas: map[string]string{"mode": "document"},
Metas: markup.ComposeSimpleDocumentMetas(),
Ctx: ctx,
}, ctx.ContextUser.Description)
if err != nil {