Skip to content

Commit 81e2ef3

Browse files
committed
Add code highlighting in issue titles
Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
1 parent 677af6a commit 81e2ef3

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

modules/templates/helper.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func NewFuncMap() []template.FuncMap {
161161
"RenderCommitMessageLink": RenderCommitMessageLink,
162162
"RenderCommitMessageLinkSubject": RenderCommitMessageLinkSubject,
163163
"RenderCommitBody": RenderCommitBody,
164+
"RenderCodeBlock": RenderCodeBlock,
164165
"RenderIssueTitle": RenderIssueTitle,
165166
"RenderEmoji": RenderEmoji,
166167
"RenderEmojiPlain": emoji.ReplaceAliases,
@@ -795,6 +796,13 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri
795796
return template.HTML(renderedMessage)
796797
}
797798

799+
var codeMatcher = regexp.MustCompile("`([^`]+)`") // capture strings of the format `code-like text`
800+
801+
func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
802+
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "<code>$1</code>") // replace with HTML <code> tags
803+
return template.HTML(htmlWithCodeTags)
804+
}
805+
798806
// RenderIssueTitle renders issue/pull title with defined post processors
799807
func RenderIssueTitle(ctx context.Context, text, urlPrefix string, metas map[string]string) template.HTML {
800808
renderedText, err := markup.RenderIssueTitle(&markup.RenderContext{

templates/repo/issue/view_title.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77
{{end}}
88
<h1>
9-
<span id="issue-title">{{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span>
9+
<span id="issue-title">{{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas | RenderCodeBlock}}</span>
1010
<span class="index">#{{.Issue.Index}}</span>
1111
<div id="edit-title-input" class="ui input" style="display: none">
1212
<input value="{{.Issue.Title}}" maxlength="255" autocomplete="off">

templates/shared/issuelist.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</div>
3636
<div class="issue-item-main f1 fc df">
3737
<div class="issue-item-top-row">
38-
<a class="title tdn" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">{{RenderEmoji .Title}}</a>
38+
<a class="title tdn issue-title" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">{{RenderEmoji .Title | RenderCodeBlock}}</a>
3939
{{if .IsPull}}
4040
{{if (index $.CommitStatuses .PullRequest.ID)}}
4141
{{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID) "root" $}}

templates/user/dashboard/feeds.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{{end}}
2525
{{else if eq .GetOpType 6}}
2626
{{$index := index .GetIssueInfos 0}}
27-
{{$.locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
27+
{{$.locale.Tr "action.create_issue" ((printf "%s/issues/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html | RenderCodeBlock}}
2828
{{else if eq .GetOpType 7}}
2929
{{$index := index .GetIssueInfos 0}}
3030
{{$.locale.Tr "action.create_pull_request" ((printf "%s/pulls/%s" .GetRepoLink $index) |Escape) $index (.ShortRepoPath|Escape) | Str2html}}
@@ -99,17 +99,17 @@
9999
</ul>
100100
</div>
101101
{{else if eq .GetOpType 6}}
102-
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji}}</span>
102+
<span class="text truncate issue title issue-title">{{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}}</span>
103103
{{else if eq .GetOpType 7}}
104-
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji}}</span>
104+
<span class="text truncate issue title issue-title">{{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}}</span>
105105
{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}}
106-
<a href="{{.GetCommentLink}}" class="text truncate issue title">{{.GetIssueTitle | RenderEmoji}}</a>
106+
<a href="{{.GetCommentLink}}" class="text truncate issue title issue-title">{{.GetIssueTitle | RenderEmoji | RenderCodeBlock}}</a>
107107
{{$comment := index .GetIssueInfos 1}}
108108
{{if gt (len $comment) 0}}<p class="text light grey">{{$comment | RenderEmoji}}</p>{{end}}
109109
{{else if eq .GetOpType 11}}
110110
<p class="text light grey">{{index .GetIssueInfos 1}}</p>
111111
{{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}}
112-
<span class="text truncate issue title">{{.GetIssueTitle | RenderEmoji}}</span>
112+
<span class="text truncate issue title issue-title">{{.GetIssueTitle | RenderEmoji | RenderCodeBlock}}</span>
113113
{{else if eq .GetOpType 25}}
114114
<p class="text light grey">{{$.locale.Tr "action.review_dismissed_reason"}}</p>
115115
<p class="text light grey">{{index .GetIssueInfos 2 | RenderEmoji}}</p>

web_src/less/_base.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ a.commit-statuses-trigger {
332332
&:extend(.unselectable);
333333
}
334334

335+
.issue-title {
336+
code {
337+
padding: 2px 4px;
338+
border-radius: 6px;
339+
background-color: var(--color-markup-code-block);
340+
}
341+
}
342+
335343
/* try to match button with no icons in height */
336344
.icon-button {
337345
padding-top: 7.42px !important;

0 commit comments

Comments
 (0)