summaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-04-03 01:48:27 +0800
committerGitHub <noreply@github.com>2024-04-02 17:48:27 +0000
commitca5c895efb91d2c2f17a83460e1753101c6f6bb1 (patch)
tree351c56aa353b6147e335dbdb3892e513690ea0e8 /templates
parenteb505b128c7b9b2459f2a5d20b5740017125178b (diff)
downloadgitea-ca5c895efb91d2c2f17a83460e1753101c6f6bb1.tar.gz
gitea-ca5c895efb91d2c2f17a83460e1753101c6f6bb1.zip
Render embedded code preview by permlink in markdown (#30234)
The permlink in markdown will be rendered as a code preview block, like GitHub Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'templates')
-rw-r--r--templates/base/markup_codepreview.tmpl25
1 files changed, 25 insertions, 0 deletions
diff --git a/templates/base/markup_codepreview.tmpl b/templates/base/markup_codepreview.tmpl
new file mode 100644
index 0000000000..c65ab28406
--- /dev/null
+++ b/templates/base/markup_codepreview.tmpl
@@ -0,0 +1,25 @@
+<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>