From 9a494af1259ea3a59706453eb16f46835720ea06 Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Mon, 2 Dec 2024 22:36:16 +0800 Subject: [PATCH 01/13] Optimize the styling of icon buttons within file-header-right (#32675) Optimize partial layout and styling to achieve uniformity and consistency. Some buttons's structure is ``, while others buttons's structure is ``. Additionally, some buttons have icons that are **14** in size, while others have icons that are **16**. Now, the layout has been unified to structure ``, and the icon size for all buttons has been standardized to the default size of **16**. Co-authored-by: wxiaoguang --- templates/repo/view_file.tmpl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 89bb371e7c7..86366ae0538 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -56,21 +56,21 @@ {{end}} - {{svg "octicon-download"}} - {{svg "octicon-copy" 14}} + {{svg "octicon-download"}} + {{svg "octicon-copy"}} {{if .EnableFeed}} - {{svg "octicon-rss" 14}} + {{svg "octicon-rss"}} {{end}} {{if .Repository.CanEnableEditor}} {{if .CanEditFile}} - {{svg "octicon-pencil"}} + {{svg "octicon-pencil"}} {{else}} {{svg "octicon-pencil"}} {{end}} {{if .CanDeleteFile}} - {{svg "octicon-trash"}} + {{svg "octicon-trash"}} {{else}} {{svg "octicon-trash"}} {{end}} From 13fbab5cf45c7546a976f0a802bbe2ddcb018f7c Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 3 Dec 2024 03:54:33 +0800 Subject: [PATCH 02/13] Remove all "floated" CSS styles (#32691) flex but don't float diff with ignoring spaces : https://github.com/go-gitea/gitea/pull/32691/files?diff=split&w=1 related pages: ### admin users ![image](https://github.com/user-attachments/assets/40dd4c46-3f5b-4a68-89b0-d0a9a806f1fc) ### milestone ![image](https://github.com/user-attachments/assets/e3efb630-f07c-4c9d-b877-71e28cddcdce) ### user account setting ![image](https://github.com/user-attachments/assets/d15609ee-016d-4aee-999a-b5455fe6185c) --- templates/admin/user/list.tmpl | 10 +++--- templates/repo/issue/milestone_new.tmpl | 2 +- templates/user/settings/account.tmpl | 48 ++++++++++++------------- web_src/css/modules/list.css | 6 ---- web_src/css/modules/menu.css | 12 ------- 5 files changed, 28 insertions(+), 50 deletions(-) diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index b6c26c85274..7e4c8854f5f 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -7,10 +7,12 @@
-
- + +
+ {{template "shared/search/combo" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.user_kind")}} +
- - - {{template "shared/search/combo" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.user_kind")}}
diff --git a/templates/repo/issue/milestone_new.tmpl b/templates/repo/issue/milestone_new.tmpl index 736a75d73a1..96a3879b802 100644 --- a/templates/repo/issue/milestone_new.tmpl +++ b/templates/repo/issue/milestone_new.tmpl @@ -5,7 +5,7 @@
{{template "repo/issue/navbar" .}} {{if and (or .CanWriteIssues .CanWritePulls) .PageIsEditMilestone}} - - +
diff --git a/web_src/js/features/repo-findfile.ts b/web_src/js/features/repo-findfile.ts index 1f151d7056c..6500978bc81 100644 --- a/web_src/js/features/repo-findfile.ts +++ b/web_src/js/features/repo-findfile.ts @@ -90,6 +90,7 @@ function filterRepoFiles(filter) { const span = document.createElement('span'); // safely escape by using textContent span.textContent = part; + span.title = span.textContent; // if the target file path is "abc/xyz", to search "bx", then the matchResult is ['a', 'b', 'c/', 'x', 'yz'] // the matchResult[odd] is matched and highlighted to red. if (index % 2 === 1) span.classList.add('ui', 'text', 'red'); From 171edfc79373fe0e80e064748c0cec8cc93aea2e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 4 Dec 2024 01:53:57 +0800 Subject: [PATCH 07/13] Fix oauth2 login methods (#32698) Regression of #32687 It should use "or" but not "and", otherwise the oauth2 methods won't show when no ENABLE_OPENID_SIGNIN --- templates/user/auth/signin_inner.tmpl | 5 +++-- templates/user/auth/signup_inner.tmpl | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/user/auth/signin_inner.tmpl b/templates/user/auth/signin_inner.tmpl index e0a19a97433..3124048d36e 100644 --- a/templates/user/auth/signin_inner.tmpl +++ b/templates/user/auth/signin_inner.tmpl @@ -48,10 +48,11 @@
{{end}}{{/*if .EnablePasswordSignInForm*/}} - {{if and .OAuth2Providers .EnableOpenIDSignIn .EnablePasswordSignInForm}} + {{$showOAuth2Methods := or .OAuth2Providers .EnableOpenIDSignIn}} + {{if and $showOAuth2Methods .EnablePasswordSignInForm}}
{{ctx.Locale.Tr "sign_in_or"}}
{{end}} - {{if and .OAuth2Providers .EnableOpenIDSignIn}} + {{if $showOAuth2Methods}} {{template "user/auth/oauth_container" .}} {{end}}
diff --git a/templates/user/auth/signup_inner.tmpl b/templates/user/auth/signup_inner.tmpl index 69690039686..41d0cd49b52 100644 --- a/templates/user/auth/signup_inner.tmpl +++ b/templates/user/auth/signup_inner.tmpl @@ -47,8 +47,8 @@ {{end}} - - {{if and .OAuth2Providers .EnableOpenIDSignIn}} + {{$showOAuth2Methods := or .OAuth2Providers .EnableOpenIDSignIn}} + {{if $showOAuth2Methods}}
{{ctx.Locale.Tr "sign_in_or"}}
{{template "user/auth/oauth_container" .}} {{end}} From 2f43536c3eb6ba20e43521f5539df8372f225652 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 4 Dec 2024 09:39:33 +0800 Subject: [PATCH 08/13] Fix issue title rendering and refactor legacy function names (#32703) Fix #32700, regression of recent markup refactoring And by the way, clarify many legacy problems: 1. Some "RenderXxx" functions do not really "render", they only call "post processors" 2. Merge "RenderEmoji | RenderCodeBlock", they are all for "simple issue title" --- models/repo/repo.go | 2 +- modules/markup/html.go | 53 ++++++++++--------- modules/markup/html_internal_test.go | 4 +- modules/markup/render.go | 4 ++ modules/templates/util_render.go | 27 ++++++---- modules/templates/util_render_test.go | 4 +- routers/web/repo/commit.go | 4 +- templates/repo/diff/compare.tmpl | 2 +- templates/repo/issue/card.tmpl | 2 +- templates/repo/issue/view_title.tmpl | 2 +- templates/repo/pulse.tmpl | 14 ++--- templates/shared/issuelist.tmpl | 2 +- templates/user/dashboard/feeds.tmpl | 8 +-- .../user/notification/notification_div.tmpl | 2 +- 14 files changed, 73 insertions(+), 57 deletions(-) diff --git a/models/repo/repo.go b/models/repo/repo.go index 4a12de9d98d..8d211caf40b 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -617,7 +617,7 @@ func (repo *Repository) CanEnableEditor() bool { // DescriptionHTML does special handles to description and return HTML string. func (repo *Repository) DescriptionHTML(ctx context.Context) template.HTML { - desc, err := markup.RenderDescriptionHTML(markup.NewRenderContext(ctx), repo.Description) + desc, err := markup.PostProcessDescriptionHTML(markup.NewRenderContext(ctx), repo.Description) if err != nil { log.Error("Failed to render description for %s (ID: %d): %v", repo.Name, repo.ID, err) return template.HTML(markup.SanitizeDescription(repo.Description)) diff --git a/modules/markup/html.go b/modules/markup/html.go index 04b768bb8ec..25628db39e4 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -159,9 +159,9 @@ func PostProcessDefault(ctx *RenderContext, input io.Reader, output io.Writer) e return postProcess(ctx, procs, input, output) } -// RenderCommitMessage will use the same logic as PostProcess, but will disable +// PostProcessCommitMessage will use the same logic as PostProcess, but will disable // the shortLinkProcessor. -func RenderCommitMessage(ctx *RenderContext, content string) (string, error) { +func PostProcessCommitMessage(ctx *RenderContext, content string) (string, error) { procs := []processor{ fullIssuePatternProcessor, comparePatternProcessor, @@ -183,11 +183,11 @@ var emojiProcessors = []processor{ emojiProcessor, } -// RenderCommitMessageSubject will use the same logic as PostProcess and -// RenderCommitMessage, but will disable the shortLinkProcessor and +// PostProcessCommitMessageSubject will use the same logic as PostProcess and +// PostProcessCommitMessage, but will disable the shortLinkProcessor and // emailAddressProcessor, will add a defaultLinkProcessor if defaultLink is set, // which changes every text node into a link to the passed default link. -func RenderCommitMessageSubject(ctx *RenderContext, defaultLink, content string) (string, error) { +func PostProcessCommitMessageSubject(ctx *RenderContext, defaultLink, content string) (string, error) { procs := []processor{ fullIssuePatternProcessor, comparePatternProcessor, @@ -211,15 +211,33 @@ func RenderCommitMessageSubject(ctx *RenderContext, defaultLink, content string) return postProcessString(ctx, procs, content) } -// RenderIssueTitle to process title on individual issue/pull page -func RenderIssueTitle(ctx *RenderContext, title string) (string, error) { - // do not render other issue/commit links in an issue's title - which in most cases is already a link. +// PostProcessIssueTitle to process title on individual issue/pull page +func PostProcessIssueTitle(ctx *RenderContext, title string) (string, error) { return postProcessString(ctx, []processor{ + issueIndexPatternProcessor, + commitCrossReferencePatternProcessor, + hashCurrentPatternProcessor, emojiShortCodeProcessor, emojiProcessor, }, title) } +// PostProcessDescriptionHTML will use similar logic as PostProcess, but will +// use a single special linkProcessor. +func PostProcessDescriptionHTML(ctx *RenderContext, content string) (string, error) { + return postProcessString(ctx, []processor{ + descriptionLinkProcessor, + emojiShortCodeProcessor, + emojiProcessor, + }, content) +} + +// PostProcessEmoji for when we want to just process emoji and shortcodes +// in various places it isn't already run through the normal markdown processor +func PostProcessEmoji(ctx *RenderContext, content string) (string, error) { + return postProcessString(ctx, emojiProcessors, content) +} + func postProcessString(ctx *RenderContext, procs []processor, content string) (string, error) { var buf strings.Builder if err := postProcess(ctx, procs, strings.NewReader(content), &buf); err != nil { @@ -228,23 +246,10 @@ func postProcessString(ctx *RenderContext, procs []processor, content string) (s return buf.String(), nil } -// RenderDescriptionHTML will use similar logic as PostProcess, but will -// use a single special linkProcessor. -func RenderDescriptionHTML(ctx *RenderContext, content string) (string, error) { - return postProcessString(ctx, []processor{ - descriptionLinkProcessor, - emojiShortCodeProcessor, - emojiProcessor, - }, content) -} - -// RenderEmoji for when we want to just process emoji and shortcodes -// in various places it isn't already run through the normal markdown processor -func RenderEmoji(ctx *RenderContext, content string) (string, error) { - return postProcessString(ctx, emojiProcessors, content) -} - func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output io.Writer) error { + if !ctx.usedByRender && ctx.RenderHelper != nil { + defer ctx.RenderHelper.CleanUp() + } // FIXME: don't read all content to memory rawHTML, err := io.ReadAll(input) if err != nil { diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index 651e674108c..9419350e615 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -252,7 +252,7 @@ func TestRender_IssueIndexPattern_NoShortPattern(t *testing.T) { testRenderIssueIndexPattern(t, "!1", "!1", NewTestRenderContext(metas)) } -func TestRender_RenderIssueTitle(t *testing.T) { +func TestRender_PostProcessIssueTitle(t *testing.T) { setting.AppURL = TestAppURL metas := map[string]string{ "format": "https://someurl.com/{user}/{repo}/{index}", @@ -260,7 +260,7 @@ func TestRender_RenderIssueTitle(t *testing.T) { "repo": "someRepo", "style": IssueNameStyleNumeric, } - actual, err := RenderIssueTitle(NewTestRenderContext(metas), "#1") + actual, err := PostProcessIssueTitle(NewTestRenderContext(metas), "#1") assert.NoError(t, err) assert.Equal(t, "#1", actual) } diff --git a/modules/markup/render.go b/modules/markup/render.go index 3b112b1a142..b239e59687b 100644 --- a/modules/markup/render.go +++ b/modules/markup/render.go @@ -57,6 +57,9 @@ type RenderOptions struct { type RenderContext struct { ctx context.Context + // the context might be used by the "render" function, but it might also be used by "postProcess" function + usedByRender bool + SidebarTocNode ast.Node RenderHelper RenderHelper @@ -182,6 +185,7 @@ func pipes() (io.ReadCloser, io.WriteCloser, func()) { } func render(ctx *RenderContext, renderer Renderer, input io.Reader, output io.Writer) error { + ctx.usedByRender = true if ctx.RenderHelper != nil { defer ctx.RenderHelper.CleanUp() } diff --git a/modules/templates/util_render.go b/modules/templates/util_render.go index 3237de5ecb1..1800747f48d 100644 --- a/modules/templates/util_render.go +++ b/modules/templates/util_render.go @@ -38,9 +38,9 @@ func (ut *RenderUtils) RenderCommitMessage(msg string, metas map[string]string) cleanMsg := template.HTMLEscapeString(msg) // we can safely assume that it will not return any error, since there // shouldn't be any special HTML. - fullMessage, err := markup.RenderCommitMessage(markup.NewRenderContext(ut.ctx).WithMetas(metas), cleanMsg) + fullMessage, err := markup.PostProcessCommitMessage(markup.NewRenderContext(ut.ctx).WithMetas(metas), cleanMsg) if err != nil { - log.Error("RenderCommitMessage: %v", err) + log.Error("PostProcessCommitMessage: %v", err) return "" } msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") @@ -65,9 +65,9 @@ func (ut *RenderUtils) RenderCommitMessageLinkSubject(msg, urlDefault string, me // we can safely assume that it will not return any error, since there // shouldn't be any special HTML. - renderedMessage, err := markup.RenderCommitMessageSubject(markup.NewRenderContext(ut.ctx).WithMetas(metas), urlDefault, template.HTMLEscapeString(msgLine)) + renderedMessage, err := markup.PostProcessCommitMessageSubject(markup.NewRenderContext(ut.ctx).WithMetas(metas), urlDefault, template.HTMLEscapeString(msgLine)) if err != nil { - log.Error("RenderCommitMessageSubject: %v", err) + log.Error("PostProcessCommitMessageSubject: %v", err) return "" } return renderCodeBlock(template.HTML(renderedMessage)) @@ -87,9 +87,9 @@ func (ut *RenderUtils) RenderCommitBody(msg string, metas map[string]string) tem return "" } - renderedMessage, err := markup.RenderCommitMessage(markup.NewRenderContext(ut.ctx).WithMetas(metas), template.HTMLEscapeString(msgLine)) + renderedMessage, err := markup.PostProcessCommitMessage(markup.NewRenderContext(ut.ctx).WithMetas(metas), template.HTMLEscapeString(msgLine)) if err != nil { - log.Error("RenderCommitMessage: %v", err) + log.Error("PostProcessCommitMessage: %v", err) return "" } return template.HTML(renderedMessage) @@ -106,12 +106,19 @@ func renderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML { // RenderIssueTitle renders issue/pull title with defined post processors func (ut *RenderUtils) RenderIssueTitle(text string, metas map[string]string) template.HTML { - renderedText, err := markup.RenderIssueTitle(markup.NewRenderContext(ut.ctx).WithMetas(metas), template.HTMLEscapeString(text)) + renderedText, err := markup.PostProcessIssueTitle(markup.NewRenderContext(ut.ctx).WithMetas(metas), template.HTMLEscapeString(text)) if err != nil { - log.Error("RenderIssueTitle: %v", err) + log.Error("PostProcessIssueTitle: %v", err) return "" } - return template.HTML(renderedText) + return renderCodeBlock(template.HTML(renderedText)) +} + +// RenderIssueSimpleTitle only renders with emoji and inline code block +func (ut *RenderUtils) RenderIssueSimpleTitle(text string) template.HTML { + ret := ut.RenderEmoji(text) + ret = renderCodeBlock(ret) + return ret } // RenderLabel renders a label @@ -174,7 +181,7 @@ func (ut *RenderUtils) RenderLabel(label *issues_model.Label) template.HTML { // RenderEmoji renders html text with emoji post processors func (ut *RenderUtils) RenderEmoji(text string) template.HTML { - renderedText, err := markup.RenderEmoji(markup.NewRenderContext(ut.ctx), template.HTMLEscapeString(text)) + renderedText, err := markup.PostProcessEmoji(markup.NewRenderContext(ut.ctx), template.HTMLEscapeString(text)) if err != nil { log.Error("RenderEmoji: %v", err) return "" diff --git a/modules/templates/util_render_test.go b/modules/templates/util_render_test.go index c0241c0a8c5..80094ab26ea 100644 --- a/modules/templates/util_render_test.go +++ b/modules/templates/util_render_test.go @@ -164,11 +164,11 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit ๐Ÿ‘ mail@domain.com @mention-user test -#123 +#123 space ` expected = strings.ReplaceAll(expected, "", " ") - assert.EqualValues(t, expected, string(newTestRenderUtils().RenderIssueTitle(testInput(), nil))) + assert.EqualValues(t, expected, string(newTestRenderUtils().RenderIssueTitle(testInput(), testMetas))) } func TestRenderMarkdownToHtml(t *testing.T) { diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 0be9689c3f5..c5652784fa0 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -394,9 +394,9 @@ func Diff(ctx *context.Context) { ctx.Data["NoteCommit"] = note.Commit ctx.Data["NoteAuthor"] = user_model.ValidateCommitWithEmail(ctx, note.Commit) rctx := renderhelper.NewRenderContextRepoComment(ctx, ctx.Repo.Repository, renderhelper.RepoCommentOptions{CurrentRefPath: path.Join("commit", util.PathEscapeSegments(commitID))}) - ctx.Data["NoteRendered"], err = markup.RenderCommitMessage(rctx, template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message, charset.ConvertOpts{})))) + ctx.Data["NoteRendered"], err = markup.PostProcessCommitMessage(rctx, template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message, charset.ConvertOpts{})))) if err != nil { - ctx.ServerError("RenderCommitMessage", err) + ctx.ServerError("PostProcessCommitMessage", err) return } } diff --git a/templates/repo/diff/compare.tmpl b/templates/repo/diff/compare.tmpl index 28419a34628..118d6478d19 100644 --- a/templates/repo/diff/compare.tmpl +++ b/templates/repo/diff/compare.tmpl @@ -187,7 +187,7 @@
{{template "shared/issueicon" .}}
- {{ctx.RenderUtils.RenderIssueTitle .PullRequest.Issue.Title ($.Repository.ComposeMetas ctx) | RenderCodeBlock}} + {{ctx.RenderUtils.RenderIssueTitle .PullRequest.Issue.Title ($.Repository.ComposeMetas ctx)}} #{{.PullRequest.Issue.Index}}
diff --git a/templates/repo/issue/card.tmpl b/templates/repo/issue/card.tmpl index 6c24419b467..2e19e86d7af 100644 --- a/templates/repo/issue/card.tmpl +++ b/templates/repo/issue/card.tmpl @@ -14,7 +14,7 @@
{{template "shared/issueicon" .}}
-
{{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{if and $.isPinnedIssueCard $.Page.IsRepoAdmin}} {{svg "octicon-x" 16}} diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index cf775f22b57..bf2ede58e48 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -13,7 +13,7 @@ {{$canEditIssueTitle := and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .Repository.IsArchived)}}

- {{ctx.RenderUtils.RenderIssueTitle .Issue.Title ($.Repository.ComposeMetas ctx) | RenderCodeBlock}} + {{ctx.RenderUtils.RenderIssueTitle .Issue.Title ($.Repository.ComposeMetas ctx)}} #{{.Issue.Index}}

diff --git a/templates/repo/pulse.tmpl b/templates/repo/pulse.tmpl index 1d7923b2f2f..52226335078 100644 --- a/templates/repo/pulse.tmpl +++ b/templates/repo/pulse.tmpl @@ -125,7 +125,7 @@ {{ctx.Locale.Tr "repo.activity.published_release_label"}} {{.TagName}} {{if not .IsTag}} - {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{end}} {{DateUtils.TimeSince .CreatedUnix}}

@@ -145,7 +145,7 @@ {{range .Activity.MergedPRs}}

{{ctx.Locale.Tr "repo.activity.merged_prs_label"}} - #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .MergedUnix}}

{{end}} @@ -164,7 +164,7 @@ {{range .Activity.OpenedPRs}}

{{ctx.Locale.Tr "repo.activity.opened_prs_label"}} - #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Issue.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .Issue.CreatedUnix}}

{{end}} @@ -183,7 +183,7 @@ {{range .Activity.ClosedIssues}}

{{ctx.Locale.Tr "repo.activity.closed_issue_label"}} - #{{.Index}} {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .ClosedUnix}}

{{end}} @@ -202,7 +202,7 @@ {{range .Activity.OpenedIssues}}

{{ctx.Locale.Tr "repo.activity.new_issue_label"}} - #{{.Index}} {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + #{{.Index}} {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{DateUtils.TimeSince .CreatedUnix}}

{{end}} @@ -220,9 +220,9 @@ {{ctx.Locale.Tr "repo.activity.unresolved_conv_label"}} #{{.Index}} {{if .IsPull}} - {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{else}} - {{.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{end}} {{DateUtils.TimeSince .UpdatedUnix}}

diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index ef2352665d5..fe5184e7d22 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -13,7 +13,7 @@
- {{ctx.RenderUtils.RenderEmoji .Title | RenderCodeBlock}} + {{.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{if .IsPull}} {{if (index $.CommitStatuses .PullRequest.ID)}} {{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID)}} diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index d3e2f7a06c2..1c1ba5566fc 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -100,11 +100,11 @@ {{ctx.Locale.Tr "action.compare_commits" $push.Len}} ยป {{end}} {{else if .GetOpType.InActions "create_issue"}} - {{index .GetIssueInfos 1 | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{index .GetIssueInfos 1 | ctx.RenderUtils.RenderIssueSimpleTitle}} {{else if .GetOpType.InActions "create_pull_request"}} - {{index .GetIssueInfos 1 | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{index .GetIssueInfos 1 | ctx.RenderUtils.RenderIssueSimpleTitle}} {{else if .GetOpType.InActions "comment_issue" "approve_pull_request" "reject_pull_request" "comment_pull"}} - {{(.GetIssueTitle ctx) | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{(.GetIssueTitle ctx) | ctx.RenderUtils.RenderIssueSimpleTitle}} {{$comment := index .GetIssueInfos 1}} {{if $comment}}
{{ctx.RenderUtils.MarkdownToHtml $comment}}
@@ -112,7 +112,7 @@ {{else if .GetOpType.InActions "merge_pull_request"}}
{{index .GetIssueInfos 1}}
{{else if .GetOpType.InActions "close_issue" "reopen_issue" "close_pull_request" "reopen_pull_request"}} - {{(.GetIssueTitle ctx) | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{(.GetIssueTitle ctx) | ctx.RenderUtils.RenderIssueSimpleTitle}} {{else if .GetOpType.InActions "pull_review_dismissed"}}
{{ctx.Locale.Tr "action.review_dismissed_reason"}}
{{index .GetIssueInfos 2 | ctx.RenderUtils.RenderEmoji}}
diff --git a/templates/user/notification/notification_div.tmpl b/templates/user/notification/notification_div.tmpl index c2bb4e2e87b..0d2371a358a 100644 --- a/templates/user/notification/notification_div.tmpl +++ b/templates/user/notification/notification_div.tmpl @@ -53,7 +53,7 @@
{{if .Issue}} - {{.Issue.Title | ctx.RenderUtils.RenderEmoji | RenderCodeBlock}} + {{.Issue.Title | ctx.RenderUtils.RenderIssueSimpleTitle}} {{else}} {{.Repository.FullName}} {{end}} From c9e582c6b6cbc7beae66d24b05be6e1d338aa81b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 4 Dec 2024 10:11:34 +0800 Subject: [PATCH 09/13] Refactor markdown editor and use it for milestone description editor (#32688) Refactor markdown editor to clarify its "preview" behavior and remove jQuery code. Close #15045 --------- Co-authored-by: silverwind --- modules/web/route.go | 5 +- options/locale/locale_en-US.ini | 1 - routers/web/web.go | 2 + templates/devtest/devtest-footer.tmpl | 2 +- templates/devtest/devtest-header.tmpl | 2 +- templates/devtest/gitea-ui.tmpl | 3 +- templates/org/settings/options.tmpl | 1 + templates/projects/new.tmpl | 11 +++- templates/repo/diff/box.tmpl | 5 +- templates/repo/diff/comment_form.tmpl | 12 ++-- templates/repo/diff/new_review.tmpl | 4 +- templates/repo/issue/comment_tab.tmpl | 7 ++- templates/repo/issue/fields/textarea.tmpl | 7 ++- templates/repo/issue/milestone_new.tmpl | 9 ++- templates/repo/issue/view_content.tmpl | 5 +- templates/repo/release/new.tmpl | 5 +- templates/repo/wiki/new.tmpl | 8 +-- templates/shared/combomarkdowneditor.tmpl | 38 +++++++++--- templates/user/settings/profile.tmpl | 1 + web_src/css/editor/combomarkdowneditor.css | 5 ++ web_src/css/repo.css | 2 +- web_src/css/review.css | 25 -------- web_src/js/features/common-form.ts | 8 ++- .../js/features/comp/ComboMarkdownEditor.ts | 58 +++++++++++-------- web_src/js/features/repo-editor.ts | 8 +-- web_src/js/features/repo-issue.ts | 5 -- web_src/js/features/repo-release.ts | 10 ---- web_src/js/features/repo-wiki.ts | 7 +-- web_src/js/index.ts | 7 ++- 29 files changed, 147 insertions(+), 116 deletions(-) diff --git a/modules/web/route.go b/modules/web/route.go index 77c411a97b9..787521dfb07 100644 --- a/modules/web/route.go +++ b/modules/web/route.go @@ -9,6 +9,7 @@ import ( "reflect" "strings" + "code.gitea.io/gitea/modules/htmlutil" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/web/middleware" @@ -214,7 +215,9 @@ func (r *Router) normalizeRequestPath(resp http.ResponseWriter, req *http.Reques normalizedPath = "/" } else if !strings.HasPrefix(normalizedPath+"/", "/v2/") { // do not respond to other requests, to simulate a real sub-path environment - http.Error(resp, "404 page not found, sub-path is: "+setting.AppSubURL, http.StatusNotFound) + resp.Header().Add("Content-Type", "text/html; charset=utf-8") + resp.WriteHeader(http.StatusNotFound) + _, _ = resp.Write([]byte(htmlutil.HTMLFormat(`404 page not found, sub-path is: %s`, setting.AppSubURL, setting.AppSubURL))) return } normalized = true diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 8da7412adeb..57d2d89c5ac 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2590,7 +2590,6 @@ diff.generated = generated diff.vendored = vendored diff.comment.add_line_comment = Add line comment diff.comment.placeholder = Leave a comment -diff.comment.markdown_info = Styling with markdown is supported. diff.comment.add_single_comment = Add single comment diff.comment.add_review_comment = Add comment diff.comment.start_review = Start review diff --git a/routers/web/web.go b/routers/web/web.go index 5ed046a9838..e89d0694493 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -485,6 +485,8 @@ func registerRoutes(m *web.Router) { m.Methods("GET, HEAD", "/*", public.FileHandlerFunc()) }, optionsCorsHandler()) + m.Post("/-/markup", reqSignIn, web.Bind(structs.MarkupOption{}), misc.Markup) + m.Group("/explore", func() { m.Get("", func(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/explore/repos") diff --git a/templates/devtest/devtest-footer.tmpl b/templates/devtest/devtest-footer.tmpl index 1c755508a5e..a1b3b86e5c4 100644 --- a/templates/devtest/devtest-footer.tmpl +++ b/templates/devtest/devtest-footer.tmpl @@ -1,3 +1,3 @@ {{/* TODO: the devtest.js is isolated from index.js, so no module is shared and many index.js functions do not work in devtest.ts */}} -{{template "base/footer" dict}} +{{template "base/footer" ctx.RootData}} diff --git a/templates/devtest/devtest-header.tmpl b/templates/devtest/devtest-header.tmpl index a5910b96e6f..ee085456406 100644 --- a/templates/devtest/devtest-header.tmpl +++ b/templates/devtest/devtest-header.tmpl @@ -1,2 +1,2 @@ -{{template "base/head" dict}} +{{template "base/head" ctx.RootData}} diff --git a/templates/devtest/gitea-ui.tmpl b/templates/devtest/gitea-ui.tmpl index 303421fe134..5b40268761d 100644 --- a/templates/devtest/gitea-ui.tmpl +++ b/templates/devtest/gitea-ui.tmpl @@ -183,8 +183,7 @@

ComboMarkdownEditor

-
ps: no JS code attached, so just a layout
- {{template "shared/combomarkdowneditor" .}} + {{template "shared/combomarkdowneditor" dict "MarkdownPreviewContext" "/owner/path"}}

Tailwind CSS Demo

diff --git a/templates/org/settings/options.tmpl b/templates/org/settings/options.tmpl index 62debfc0aef..3b817d068b5 100644 --- a/templates/org/settings/options.tmpl +++ b/templates/org/settings/options.tmpl @@ -23,6 +23,7 @@
+ {{/* it is rendered as markdown, but the length is limited, so at the moment we do not use the markdown editor here */}}
diff --git a/templates/projects/new.tmpl b/templates/projects/new.tmpl index bd173b54bce..a936079c466 100644 --- a/templates/projects/new.tmpl +++ b/templates/projects/new.tmpl @@ -18,7 +18,16 @@
- + {{/* TODO: repo-level project and org-level project have different behaviros to render */}} + {{/* the "Repository" is nil when the project is org-level */}} + {{template "shared/combomarkdowneditor" (dict + "MarkdownPreviewInRepo" $.Repository + "MarkdownPreviewContext" (Iif $.Repository "" .HomeLink) + "MarkdownPreviewMode" (Iif $.Repository "comment") + "TextareaName" "content" + "TextareaContent" .content + "TextareaPlaceholder" (ctx.Locale.Tr "repo.projects.description_placeholder") + )}}
{{if not .PageIsEditProjects}} diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 20e0c9db668..0f1458bfbfd 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -240,8 +240,9 @@