mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-27 19:13:48 +08:00
81467e6f35
* Change to display SVG files as images * Remove unsafe styles from SVG CSP * Add integration test to test SVG headers * Add config setting to disable SVG rendering * Add test for img tag when loading SVG image * Remove the Raw view button for svg files since we don't fully support this * Fix copyright year * Rename and move config setting * Add setting to cheat sheet in docs * Fix so that comment matches cheat sheet * Add allowing styles in CSP based on pull request feedback * Re-enable raw button since we show SVG styles now * Change so that SVG files are editable * Add UI to toggle between source and rendered image for SVGs * Change to show blame button for SVG images * Fix to update ctx data * Add test for DetectContentType when file is longer than sniffLen Co-authored-by: Jonathan Tran <jon@allspice.io> Co-authored-by: Kyle D <kdumontnu@gmail.com>
129 lines
5.6 KiB
Handlebars
129 lines
5.6 KiB
Handlebars
<div class="{{TabSizeClass .Editorconfig .FileName}} non-diff-file-content">
|
|
<h4 class="file-header ui top attached header df ac sb">
|
|
<div class="file-header-left df ac">
|
|
{{if .ReadmeInList}}
|
|
{{svg "octicon-book" 16 "mr-3"}}
|
|
<strong>{{.FileName}}</strong>
|
|
{{else}}
|
|
<div class="file-info text grey normal mono">
|
|
{{if .FileIsSymlink}}
|
|
<div class="file-info-entry">
|
|
{{.i18n.Tr "repo.symbolic_link"}}
|
|
</div>
|
|
{{end}}
|
|
{{if .NumLinesSet}}
|
|
<div class="file-info-entry">
|
|
{{.NumLines}} {{.i18n.Tr (TrN .i18n.Lang .NumLines "repo.line" "repo.lines") }}
|
|
</div>
|
|
{{end}}
|
|
{{if .FileSize}}
|
|
<div class="file-info-entry">
|
|
{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.i18n.Tr "repo.stored_lfs"}}){{end}}
|
|
</div>
|
|
{{end}}
|
|
{{if .LFSLock}}
|
|
<div class="file-info-entry ui poping up" data-content="{{.LFSLockHint}}">
|
|
{{svg "octicon-lock" 16 "mr-2"}}
|
|
<a href="{{AppSubUrl}}/{{.LFSLock.Owner.Name}}">{{.LFSLockOwner}}</a>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
{{if not .ReadmeInList}}
|
|
<div class="file-header-right file-actions df ac">
|
|
{{if .HasSourceRenderedToggle}}
|
|
<div class="ui compact icon buttons">
|
|
<a href="{{$.Link}}?display=source" class="ui tiny basic button poping up {{if .IsDisplayingSource}}active{{end}}" data-content="{{.i18n.Tr "repo.file_view_source"}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-code"}}</a>
|
|
<a href="{{$.Link}}" class="ui tiny basic button poping up {{if .IsDisplayingRendered}}active{{end}}" data-content="{{.i18n.Tr "repo.file_view_rendered"}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-file"}}</a>
|
|
</div>
|
|
{{end}}
|
|
<div class="ui buttons mr-2">
|
|
<a class="ui mini basic button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
|
|
{{if not .IsViewCommit}}
|
|
<a class="ui mini basic button" href="{{.RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
|
|
{{end}}
|
|
{{if .IsRepresentableAsText}}
|
|
<a class="ui mini basic button" href="{{.RepoLink}}/blame/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.blame"}}</a>
|
|
{{end}}
|
|
<a class="ui mini basic button" href="{{.RepoLink}}/commits/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
|
|
</div>
|
|
{{if .Repository.CanEnableEditor}}
|
|
{{if .CanEditFile}}
|
|
<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><span class="btn-octicon poping up" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-pencil"}}</span></a>
|
|
{{else}}
|
|
<span class="btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-pencil"}}</span>
|
|
{{end}}
|
|
{{if .CanDeleteFile}}
|
|
<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><span class="btn-octicon btn-octicon-danger poping up" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-trashcan"}}</span></a>
|
|
{{else}}
|
|
<span class="btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted">{{svg "octicon-trashcan"}}</span>
|
|
{{end}}
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
</h4>
|
|
<div class="ui attached table unstackable segment">
|
|
<div class="file-view {{if .IsMarkup}}{{.MarkupType}} markdown{{else if .IsRenderedHTML}}plain-text{{else if .IsTextSource}}code-view{{end}}">
|
|
{{if .IsMarkup}}
|
|
{{if .FileContent}}{{.FileContent | Safe}}{{end}}
|
|
{{else if .IsRenderedHTML}}
|
|
<pre>{{if .FileContent}}{{.FileContent | Str2html}}{{end}}</pre>
|
|
{{else if not .IsTextSource}}
|
|
<div class="view-raw ui center">
|
|
{{if .IsImageFile}}
|
|
<img src="{{EscapePound $.RawFileLink}}">
|
|
{{else if .IsVideoFile}}
|
|
<video controls src="{{EscapePound $.RawFileLink}}">
|
|
<strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
|
|
</video>
|
|
{{else if .IsAudioFile}}
|
|
<audio controls src="{{EscapePound $.RawFileLink}}">
|
|
<strong>{{.i18n.Tr "repo.audio_not_supported_in_browser"}}</strong>
|
|
</audio>
|
|
{{else if .IsPDFFile}}
|
|
<iframe width="100%" height="600px" src="{{StaticUrlPrefix}}/vendor/plugins/pdfjs/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
|
|
{{else}}
|
|
<a href="{{EscapePound $.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.i18n.Tr "repo.file_view_raw"}}</a>
|
|
{{end}}
|
|
</div>
|
|
{{else if .FileSize}}
|
|
{{if .IsFileTooLarge}}
|
|
<table>
|
|
<tbody>
|
|
<tr>
|
|
<td><strong>{{.i18n.Tr "repo.file_too_large"}}</strong></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
{{else}}
|
|
<table>
|
|
<tbody>
|
|
{{range $line, $code := .FileContent}}
|
|
<tr>
|
|
<td id="L{{$line}}" class="lines-num">
|
|
<span id="L{{$line}}" data-line-number="{{$line}}"></span>
|
|
</td>
|
|
<td rel="L{{$line}}" class="lines-code chroma">
|
|
<code class="code-inner">{{$code | Safe}}</code>
|
|
</td>
|
|
</tr>
|
|
{{end}}
|
|
</tbody>
|
|
</table>
|
|
{{end}}
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function submitDeleteForm() {
|
|
var message = prompt("{{.i18n.Tr "repo.delete_confirm_message"}}\n\n{{.i18n.Tr "repo.delete_commit_summary"}}", "Delete '{{.TreeName}}'");
|
|
if (message != null) {
|
|
$("#delete-message").val(message);
|
|
$("#delete-file-form").submit()
|
|
}
|
|
}
|
|
</script>
|