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

Refactor markup render system (#32589)

This PR mainly moves some code and introduces `RenderContext.WithXxx`
functions
This commit is contained in:
wxiaoguang
2024-11-22 13:48:09 +08:00
committed by GitHub
parent 81ac8d914c
commit c4e27cb27b
49 changed files with 486 additions and 626 deletions

View File

@@ -51,16 +51,14 @@ func toReleaseLink(ctx *context.Context, act *activities_model.Action) string {
// renderMarkdown creates a minimal markdown render context from an action.
// If rendering fails, the original markdown text is returned
func renderMarkdown(ctx *context.Context, act *activities_model.Action, content string) template.HTML {
markdownCtx := &markup.RenderContext{
Ctx: ctx,
Links: markup.Links{
markdownCtx := markup.NewRenderContext(ctx).
WithLinks(markup.Links{
Base: act.GetRepoLink(ctx),
},
Metas: map[string]string{ // FIXME: not right here, it should use issue to compose the metas
}).
WithMetas(map[string]string{ // FIXME: not right here, it should use issue to compose the metas
"user": act.GetRepoUserName(ctx),
"repo": act.GetRepoName(ctx),
},
}
})
markdown, err := markdown.RenderString(markdownCtx, content)
if err != nil {
return templates.SanitizeHTML(content) // old code did so: use SanitizeHTML to render in tmpl
@@ -296,14 +294,13 @@ func releasesToFeedItems(ctx *context.Context, releases []*repo_model.Release) (
}
link := &feeds.Link{Href: rel.HTMLURL()}
content, err = markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Repo: rel.Repo,
Links: markup.Links{
content, err = markdown.RenderString(markup.NewRenderContext(ctx).
WithRepoFacade(rel.Repo).
WithLinks(markup.Links{
Base: rel.Repo.Link(),
},
Metas: rel.Repo.ComposeMetas(ctx),
}, rel.Note)
}).
WithMetas(rel.Repo.ComposeMetas(ctx)),
rel.Note)
if err != nil {
return nil, err
}

View File

@@ -41,13 +41,10 @@ func showUserFeed(ctx *context.Context, formatType string) {
return
}
ctxUserDescription, err := markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Links: markup.Links{
Base: ctx.ContextUser.HTMLURL(),
},
Metas: markup.ComposeSimpleDocumentMetas(),
}, ctx.ContextUser.Description)
ctxUserDescription, err := markdown.RenderString(markup.NewRenderContext(ctx).
WithLinks(markup.Links{Base: ctx.ContextUser.HTMLURL()}).
WithMetas(markup.ComposeSimpleDocumentMetas()),
ctx.ContextUser.Description)
if err != nil {
ctx.ServerError("RenderString", err)
return