From 81e2ef3c0a3da6be92f739f822152f029800b9cc Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Fri, 14 Oct 2022 13:20:44 +0000 Subject: [PATCH 1/8] Add `code` highlighting in issue titles Signed-off-by: Yarden Shoham --- modules/templates/helper.go | 8 ++++++++ templates/repo/issue/view_title.tmpl | 2 +- templates/shared/issuelist.tmpl | 2 +- templates/user/dashboard/feeds.tmpl | 10 +++++----- web_src/less/_base.less | 8 ++++++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index a8e4075248dd..1d60719d740f 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -161,6 +161,7 @@ func NewFuncMap() []template.FuncMap { "RenderCommitMessageLink": RenderCommitMessageLink, "RenderCommitMessageLinkSubject": RenderCommitMessageLinkSubject, "RenderCommitBody": RenderCommitBody, + "RenderCodeBlock": RenderCodeBlock, "RenderIssueTitle": RenderIssueTitle, "RenderEmoji": RenderEmoji, "RenderEmojiPlain": emoji.ReplaceAliases, @@ -795,6 +796,13 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri return template.HTML(renderedMessage) } +var codeMatcher = regexp.MustCompile("`([^`]+)`") // capture strings of the format `code-like text` + +func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML { + htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "$1") // replace with HTML tags + return template.HTML(htmlWithCodeTags) +} + // RenderIssueTitle renders issue/pull title with defined post processors func RenderIssueTitle(ctx context.Context, text, urlPrefix string, metas map[string]string) template.HTML { renderedText, err := markup.RenderIssueTitle(&markup.RenderContext{ diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 3141e81808bf..58f4722e28a7 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -6,7 +6,7 @@ {{end}}

- {{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas}} + {{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas | RenderCodeBlock}} #{{.Issue.Index}}
- {{RenderEmoji .Title}} + {{RenderEmoji .Title | RenderCodeBlock}} {{if .IsPull}} {{if (index $.CommitStatuses .PullRequest.ID)}} {{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID) "root" $}} diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 1862f32b6b69..c550220a17d5 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -24,7 +24,7 @@ {{end}} {{else if eq .GetOpType 6}} {{$index := index .GetIssueInfos 0}} - {{$.locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}} + {{$.locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html | RenderCodeBlock}} {{else if eq .GetOpType 7}} {{$index := index .GetIssueInfos 0}} {{$.locale.Tr "action.create_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}} @@ -99,17 +99,17 @@
{{else if eq .GetOpType 6}} - {{index .GetIssueInfos 1 | RenderEmoji}} + {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} {{else if eq .GetOpType 7}} - {{index .GetIssueInfos 1 | RenderEmoji}} + {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} {{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}} - {{.GetIssueTitle | RenderEmoji}} + {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} {{$comment := index .GetIssueInfos 1}} {{if gt (len $comment) 0}}

{{$comment | RenderEmoji}}

{{end}} {{else if eq .GetOpType 11}}

{{index .GetIssueInfos 1}}

{{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}} - {{.GetIssueTitle | RenderEmoji}} + {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} {{else if eq .GetOpType 25}}

{{$.locale.Tr "action.review_dismissed_reason"}}

{{index .GetIssueInfos 2 | RenderEmoji}}

diff --git a/web_src/less/_base.less b/web_src/less/_base.less index c66cabd8a196..b2c1c2bcce03 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -332,6 +332,14 @@ a.commit-statuses-trigger { &:extend(.unselectable); } +.issue-title { + code { + padding: 2px 4px; + border-radius: 6px; + background-color: var(--color-markup-code-block); + } +} + /* try to match button with no icons in height */ .icon-button { padding-top: 7.42px !important; From 6d5d3dad977899099e9a622f23b024cedf061af8 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Fri, 14 Oct 2022 13:32:31 +0000 Subject: [PATCH 2/8] Remove unnecessary `RenderCodeBlock` Signed-off-by: Yarden Shoham --- templates/user/dashboard/feeds.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index c550220a17d5..335d47496074 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -24,7 +24,7 @@ {{end}} {{else if eq .GetOpType 6}} {{$index := index .GetIssueInfos 0}} - {{$.locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html | RenderCodeBlock}} + {{$.locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}} {{else if eq .GetOpType 7}} {{$index := index .GetIssueInfos 0}} {{$.locale.Tr "action.create_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}} From ee986c33db63ea9665000cbd23df98c665528406 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 15 Oct 2022 12:04:08 +0300 Subject: [PATCH 3/8] Update modules/templates/helper.go Co-authored-by: Gusted --- modules/templates/helper.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 1d60719d740f..b4ecd3f8e484 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -796,7 +796,8 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri return template.HTML(renderedMessage) } -var codeMatcher = regexp.MustCompile("`([^`]+)`") // capture strings of the format `code-like text` +// Match text that is between back ticks. +var codeMatcher = regexp.MustCompile("`([^`]+)`") func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML { htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "$1") // replace with HTML tags From e2661ad729d6de172a10302a16ca290d69aa025d Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 15 Oct 2022 12:04:17 +0300 Subject: [PATCH 4/8] Update web_src/less/_base.less Co-authored-by: Gusted --- web_src/less/_base.less | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/web_src/less/_base.less b/web_src/less/_base.less index b2c1c2bcce03..2abebe5c7d15 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -332,14 +332,11 @@ a.commit-statuses-trigger { &:extend(.unselectable); } -.issue-title { - code { - padding: 2px 4px; - border-radius: 6px; - background-color: var(--color-markup-code-block); - } +.issue-title code { + padding: 2px 4px; + border-radius: 6px; + background-color: var(--color-markup-code-block); } - /* try to match button with no icons in height */ .icon-button { padding-top: 7.42px !important; From 2ba18c38702addd2b9710f70b8b0bf563d595fcb Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 15 Oct 2022 09:42:38 +0000 Subject: [PATCH 5/8] Increase issue-title code importance Signed-off-by: Yarden Shoham --- web_src/less/_base.less | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web_src/less/_base.less b/web_src/less/_base.less index 2abebe5c7d15..cb847e48f458 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -333,9 +333,9 @@ a.commit-statuses-trigger { } .issue-title code { - padding: 2px 4px; - border-radius: 6px; - background-color: var(--color-markup-code-block); + padding: 2px 4px !important; + border-radius: 6px !important; + background-color: var(--color-markup-code-block) !important; } /* try to match button with no icons in height */ .icon-button { From 6a6ea5831834a0c50ce8a5b5794ffbc30b73a739 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 15 Oct 2022 19:39:41 +0800 Subject: [PATCH 6/8] Update modules/templates/helper.go --- modules/templates/helper.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index b4ecd3f8e484..1a2be770b4fb 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -799,6 +799,8 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri // Match text that is between back ticks. var codeMatcher = regexp.MustCompile("`([^`]+)`") +// RenderCodeBlock renders "`…`" as highlighted "" block. +// Intended for issue and PR titles, these containers should have styles for "" elements func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML { htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "$1") // replace with HTML tags return template.HTML(htmlWithCodeTags) From 1752128af0177a18d6f6776f42f528e9ba03bbe7 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 15 Oct 2022 18:03:25 +0800 Subject: [PATCH 7/8] fix code styles in feed list --- templates/user/dashboard/feeds.tmpl | 8 ++++---- web_src/less/_base.less | 6 +++--- web_src/less/_dashboard.less | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/templates/user/dashboard/feeds.tmpl b/templates/user/dashboard/feeds.tmpl index 335d47496074..94bbbc470aa3 100644 --- a/templates/user/dashboard/feeds.tmpl +++ b/templates/user/dashboard/feeds.tmpl @@ -99,17 +99,17 @@
{{else if eq .GetOpType 6}} - {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} + {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} {{else if eq .GetOpType 7}} - {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} + {{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}} {{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}} - {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} + {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} {{$comment := index .GetIssueInfos 1}} {{if gt (len $comment) 0}}

{{$comment | RenderEmoji}}

{{end}} {{else if eq .GetOpType 11}}

{{index .GetIssueInfos 1}}

{{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}} - {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} + {{.GetIssueTitle | RenderEmoji | RenderCodeBlock}} {{else if eq .GetOpType 25}}

{{$.locale.Tr "action.review_dismissed_reason"}}

{{index .GetIssueInfos 2 | RenderEmoji}}

diff --git a/web_src/less/_base.less b/web_src/less/_base.less index cb847e48f458..2abebe5c7d15 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -333,9 +333,9 @@ a.commit-statuses-trigger { } .issue-title code { - padding: 2px 4px !important; - border-radius: 6px !important; - background-color: var(--color-markup-code-block) !important; + padding: 2px 4px; + border-radius: 6px; + background-color: var(--color-markup-code-block); } /* try to match button with no icons in height */ .icon-button { diff --git a/web_src/less/_dashboard.less b/web_src/less/_dashboard.less index 570d77272939..e9a906cbedaa 100644 --- a/web_src/less/_dashboard.less +++ b/web_src/less/_dashboard.less @@ -141,10 +141,9 @@ } code { - padding: 1px; - font-size: 85%; - background-color: rgba(0, 0, 0, .04); + padding: 2px 4px; border-radius: 3px; + background-color: var(--color-markup-code-block); word-break: break-all; } From d9a526cccbc1ccc6a791c2a72890104674f7a730 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 15 Oct 2022 16:29:26 +0000 Subject: [PATCH 8/8] Format code --- modules/templates/helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 1a2be770b4fb..e10beae1d958 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -796,7 +796,7 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri return template.HTML(renderedMessage) } -// Match text that is between back ticks. +// Match text that is between back ticks. var codeMatcher = regexp.MustCompile("`([^`]+)`") // RenderCodeBlock renders "`…`" as highlighted "" block.