0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-05-19 20:04:01 +02:00
gitea/templates/base/markup_codepreview.tmpl
Giteabot 6bf6fa8de0
Render embedded code preview by permlink in markdown (#30234) (#30249)
Backport #30234 by wxiaoguang

The permlink in markdown will be rendered as a code preview block, like GitHub

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
2024-04-03 02:20:16 +08:00

26 lines
1.2 KiB
Handlebars

<div class="code-preview-container file-content">
<div class="code-preview-header">
<a href="{{.FullURL}}" class="muted" rel="nofollow">{{.FilePath}}</a>
{{$link := HTMLFormat `<a href="%s/src/commit/%s" rel="nofollow">%s</a>` .RepoLink .CommitID (.CommitID | ShortSha) -}}
{{- if eq .LineStart .LineStop -}}
{{ctx.Locale.Tr "repo.code_preview_line_in" .LineStart $link}}
{{- else -}}
{{ctx.Locale.Tr "repo.code_preview_line_from_to" .LineStart .LineStop $link}}
{{- end}}
</div>
<table class="file-view">
<tbody>
{{- range $idx, $line := .HighlightLines -}}
<tr>
<td class="lines-num"><span data-line-number="{{$line.Num}}"></span></td>
{{- if $.EscapeStatus.Escaped -}}
{{- $lineEscapeStatus := index $.LineEscapeStatus $idx -}}
<td class="lines-escape">{{if $lineEscapeStatus.Escaped}}<a href="#" class="toggle-escape-button btn interact-bg" title="{{if $lineEscapeStatus.HasInvisible}}{{ctx.Locale.Tr "repo.invisible_runes_line"}} {{end}}{{if $lineEscapeStatus.HasAmbiguous}}{{ctx.Locale.Tr "repo.ambiguous_runes_line"}}{{end}}"></a>{{end}}</td>
{{- end}}
<td class="lines-code chroma"><code class="code-inner">{{$line.FormattedContent}}</code></td>
</tr>
{{- end -}}
</tbody>
</table>
</div>