aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-22 13:48:09 +0800
committerGitHub <noreply@github.com>2024-11-22 05:48:09 +0000
commitc4e27cb27b99dd9528c999fdc8b1073f28be6313 (patch)
treebbd065423fa48e09553918d23bdc7c5daef6e8bd /services
parent81ac8d914cf5fdfaad3c206223ad0ace1e8c1dcd (diff)
downloadgitea-c4e27cb27b99dd9528c999fdc8b1073f28be6313.tar.gz
gitea-c4e27cb27b99dd9528c999fdc8b1073f28be6313.zip
Refactor markup render system (#32589)
This PR mainly moves some code and introduces `RenderContext.WithXxx` functions
Diffstat (limited to 'services')
-rw-r--r--services/context/org.go4
-rw-r--r--services/mailer/mail.go14
-rw-r--r--services/mailer/mail_release.go13
3 files changed, 11 insertions, 20 deletions
diff --git a/services/context/org.go b/services/context/org.go
index 132ce19a31..bf482fa754 100644
--- a/services/context/org.go
+++ b/services/context/org.go
@@ -259,9 +259,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
ctx.Data["IsFollowing"] = ctx.Doer != nil && user_model.IsFollowing(ctx, ctx.Doer.ID, ctx.ContextUser.ID)
if len(ctx.ContextUser.Description) != 0 {
- content, err := markdown.RenderString(&markup.RenderContext{
- Ctx: ctx,
- }, ctx.ContextUser.Description)
+ content, err := markdown.RenderString(markup.NewRenderContext(ctx), ctx.ContextUser.Description)
if err != nil {
ctx.ServerError("RenderString", err)
return
diff --git a/services/mailer/mail.go b/services/mailer/mail.go
index 23c91595b7..162e497dc0 100644
--- a/services/mailer/mail.go
+++ b/services/mailer/mail.go
@@ -219,15 +219,11 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
}
// This is the body of the new issue or comment, not the mail body
- body, err := markdown.RenderString(&markup.RenderContext{
- Ctx: ctx,
- Repo: ctx.Issue.Repo,
- Links: markup.Links{
- AbsolutePrefix: true,
- Base: ctx.Issue.Repo.HTMLURL(),
- },
- Metas: ctx.Issue.Repo.ComposeMetas(ctx),
- }, ctx.Content)
+ body, err := markdown.RenderString(markup.NewRenderContext(ctx).
+ WithRepoFacade(ctx.Issue.Repo).
+ WithLinks(markup.Links{AbsolutePrefix: true, Base: ctx.Issue.Repo.HTMLURL()}).
+ WithMetas(ctx.Issue.Repo.ComposeMetas(ctx)),
+ ctx.Content)
if err != nil {
return nil, err
}
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go
index 01a8929e2d..3298c2273a 100644
--- a/services/mailer/mail_release.go
+++ b/services/mailer/mail_release.go
@@ -56,14 +56,11 @@ func mailNewRelease(ctx context.Context, lang string, tos []*user_model.User, re
locale := translation.NewLocale(lang)
var err error
- rel.RenderedNote, err = markdown.RenderString(&markup.RenderContext{
- Ctx: ctx,
- Repo: rel.Repo,
- Links: markup.Links{
- Base: rel.Repo.HTMLURL(),
- },
- Metas: rel.Repo.ComposeMetas(ctx),
- }, rel.Note)
+ rel.RenderedNote, err = markdown.RenderString(markup.NewRenderContext(ctx).
+ WithRepoFacade(rel.Repo).
+ WithLinks(markup.Links{Base: rel.Repo.HTMLURL()}).
+ WithMetas(rel.Repo.ComposeMetas(ctx)),
+ rel.Note)
if err != nil {
log.Error("markdown.RenderString(%d): %v", rel.RepoID, err)
return