0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-17 15:31:06 +01:00

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 <wxiaoguang@gmail.com>
This commit is contained in:
silverwind 2023-08-31 07:01:01 +02:00 committed by GitHub
parent c35b16a9a4
commit 3d109861dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 10 deletions

View file

@ -108,10 +108,9 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri
// Match text that is between back ticks. // Match text that is between back ticks.
var codeMatcher = regexp.MustCompile("`([^`]+)`") var codeMatcher = regexp.MustCompile("`([^`]+)`")
// RenderCodeBlock renders "`…`" as highlighted "<code>" block. // RenderCodeBlock renders "`…`" as highlighted "<code>" block, intended for issue and PR titles
// Intended for issue and PR titles, these containers should have styles for "<code>" elements
func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML { func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "<code>$1</code>") // replace with HTML <code> tags htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), `<code class="inline-code-block">$1</code>`) // replace with HTML <code> tags
return template.HTML(htmlWithCodeTags) return template.HTML(htmlWithCodeTags)
} }

View file

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

View file

@ -454,7 +454,7 @@ a.label,
background: var(--color-hover); background: var(--color-hover);
} }
.issue-title code { .inline-code-block {
padding: 2px 4px; padding: 2px 4px;
border-radius: var(--border-radius-medium); border-radius: var(--border-radius-medium);
background-color: var(--color-markup-code-block); background-color: var(--color-markup-code-block);

View file

@ -236,10 +236,6 @@
} }
} }
.repository.file.list #repo-desc {
font-size: 1.2em;
}
.repository.file.list .repo-path { .repository.file.list .repo-path {
word-break: break-word; word-break: break-word;
} }