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:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user