Skip to content

Commit 3d10986

Browse files
Render code blocks in repo description (#26830)
Backtick syntax now works in repo description too. Also, I replaced the CSS for this was a new single class, making it more flexible and not dependent on a parent. Also, very slightly reduced font size from 16.8px to 16px. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent c35b16a commit 3d10986

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

modules/templates/util_render.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri
108108
// Match text that is between back ticks.
109109
var codeMatcher = regexp.MustCompile("`([^`]+)`")
110110

111-
// RenderCodeBlock renders "`…`" as highlighted "<code>" block.
112-
// Intended for issue and PR titles, these containers should have styles for "<code>" elements
111+
// RenderCodeBlock renders "`…`" as highlighted "<code>" block, intended for issue and PR titles
113112
func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
114-
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "<code>$1</code>") // replace with HTML <code> tags
113+
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), `<code class="inline-code-block">$1</code>`) // replace with HTML <code> tags
115114
return template.HTML(htmlWithCodeTags)
116115
}
117116

templates/repo/home.tmpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
{{template "repo/code/recently_pushed_new_branches" .}}
77
{{if and (not .HideRepoInfo) (not .IsBlame)}}
88
<div class="ui repo-description">
9-
<div id="repo-desc">
9+
<div id="repo-desc" class="gt-font-16">
1010
{{$description := .Repository.DescriptionHTML $.Context}}
11-
{{if $description}}<span class="description">{{$description}}</span>{{else if .IsRepositoryAdmin}}<span class="no-description text-italic">{{.locale.Tr "repo.no_desc"}}</span>{{end}}
11+
{{if $description}}<span class="description">{{$description | RenderCodeBlock}}</span>{{else if .IsRepositoryAdmin}}<span class="no-description text-italic">{{.locale.Tr "repo.no_desc"}}</span>{{end}}
1212
<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
1313
</div>
1414
{{if .RepoSearchEnabled}}

web_src/css/base.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ a.label,
454454
background: var(--color-hover);
455455
}
456456

457-
.issue-title code {
457+
.inline-code-block {
458458
padding: 2px 4px;
459459
border-radius: var(--border-radius-medium);
460460
background-color: var(--color-markup-code-block);

web_src/css/repo.css

-4
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,6 @@
236236
}
237237
}
238238

239-
.repository.file.list #repo-desc {
240-
font-size: 1.2em;
241-
}
242-
243239
.repository.file.list .repo-path {
244240
word-break: break-word;
245241
}

0 commit comments

Comments
 (0)