view_file.tmpl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <div id="file-content" class="{{TabSizeClass .Editorconfig .FileName}}">
  2. <h4 class="ui top attached header" id="{{if .ReadmeExist}}repo-readme{{else}}repo-read-file{{end}}">
  3. {{if .ReadmeExist}}
  4. <i class="octicon octicon-book"></i>
  5. {{if .ReadmeInList}}
  6. <strong>{{.FileName}}</strong>
  7. {{else}}
  8. <strong>{{.FileName}}</strong> <span class="text grey normal">{{FileSize .FileSize}}</span>
  9. {{end}}
  10. {{else}}
  11. <i class="octicon octicon-file-text ui left"></i>
  12. <strong>{{.FileName}}</strong> <span class="text grey normal">{{FileSize .FileSize}}</span>
  13. {{end}}
  14. {{if not .ReadmeInList}}
  15. <div class="ui right file-actions">
  16. <div class="ui buttons">
  17. {{if not .IsViewCommit}}
  18. <a class="ui button" href="{{.RepoLink}}/src/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
  19. {{end}}
  20. <a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
  21. <a class="ui button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
  22. </div>
  23. {{if .Repository.CanEnableEditor}}
  24. {{if .CanEditFile}}
  25. <a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-pencil btn-octicon poping up" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
  26. {{else}}
  27. <i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
  28. {{end}}
  29. {{if .CanDeleteFile}}
  30. <a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
  31. {{else}}
  32. <i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
  33. {{end}}
  34. {{end}}
  35. </div>
  36. {{end}}
  37. </h4>
  38. <div class="ui unstackable attached table segment">
  39. <div id="{{if .IsIPythonNotebook}}ipython-notebook{{end}}" class="file-view {{if .IsMarkdown}}markdown{{else if .IsIPythonNotebook}}ipython-notebook{{else if .ReadmeInList}}plain-text{{else if and .IsTextFile}}code-view{{end}} has-emoji">
  40. {{if .IsMarkdown}}
  41. {{if .FileContent}}{{.FileContent | Str2HTML}}{{end}}
  42. {{else if .IsIPythonNotebook}}
  43. <script>
  44. $.getJSON("{{.RawFileLink}}", null, function(notebook_json) {
  45. var notebook = nb.parse(notebook_json);
  46. var rendered = notebook.render();
  47. $.ajax({
  48. type: "POST",
  49. url: '{{AppSubURL}}/-/api/sanitize_ipynb',
  50. data: rendered.outerHTML,
  51. processData: false,
  52. contentType: false,
  53. }).done(function(data) {
  54. $("#ipython-notebook").append(data);
  55. $("#ipython-notebook code").each(function(i, block) {
  56. $(block).addClass("py").addClass("python");
  57. hljs.highlightBlock(block);
  58. });
  59. // Overwrite image method to append proper prefix to the source URL
  60. var renderer = new marked.Renderer();
  61. var context = '{{.RawFileLink}}';
  62. context = context.substring(0, context.lastIndexOf("/"));
  63. renderer.image = function (href, title, text) {
  64. return `<img src="${context}/${href}"`
  65. };
  66. $("#ipython-notebook .nb-markdown-cell").each(function(i, markdown) {
  67. $(markdown).html(marked($(markdown).html(), {renderer: renderer}));
  68. });
  69. });
  70. });
  71. </script>
  72. {{else if .ReadmeInList}}
  73. {{if .FileContent}}{{.FileContent | Str2HTML}}{{end}}
  74. {{else if not .IsTextFile}}
  75. <div class="view-raw ui center">
  76. {{if .IsImageFile}}
  77. <img src="{{EscapePound $.RawFileLink}}">
  78. {{else if .IsVideoFile}}
  79. <video controls src="{{EscapePound $.RawFileLink}}">
  80. <strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
  81. </video>
  82. {{else if .IsPDFFile}}
  83. <iframe width="100%" height="600px" src="{{AppSubURL}}/plugins/pdfjs-1.4.20/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
  84. {{else}}
  85. <a href="{{EscapePound $.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.i18n.Tr "repo.file_view_raw"}}</a>
  86. {{end}}
  87. </div>
  88. {{else if .FileSize}}
  89. <table>
  90. <tbody>
  91. <tr>
  92. {{if .IsFileTooLarge}}
  93. <td><strong>{{.i18n.Tr "repo.file_too_large"}}</strong></td>
  94. {{else}}
  95. <td class="lines-num">{{.LineNums}}</td>
  96. <td class="lines-code"><pre><code class="{{.HighlightClass}}"><ol class="linenums">{{.FileContent}}</ol></code></pre></td>
  97. {{end}}
  98. </tr>
  99. </tbody>
  100. </table>
  101. {{end}}
  102. </div>
  103. </div>
  104. </div>
  105. <script>
  106. function submitDeleteForm() {
  107. var message = prompt("{{.i18n.Tr "repo.delete_confirm_message"}}\n\n{{.i18n.Tr "repo.delete_commit_summary"}}", "Delete '{{.TreeName}}'");
  108. if (message != null) {
  109. $("#delete-message").val(message);
  110. $("#delete-file-form").submit()
  111. }
  112. }
  113. </script>