Browse Source

Render plain text README.txt monospaced (#2721)

Signed-off-by: Jonas Franz <info@jonasfranz.software>
Jonas Franz 2 years ago
parent
commit
f4190f8df8
4 changed files with 12 additions and 5 deletions
  1. 1 1
      public/css/index.css
  2. 4 0
      public/less/_repository.less
  3. 3 2
      routers/repo/view.go
  4. 4 2
      templates/repo/view_file.tmpl

File diff suppressed because it is too large
+ 1 - 1
public/css/index.css


+ 4 - 0
public/less/_repository.less

@@ -270,6 +270,10 @@
270 270
 				}
271 271
 			}
272 272
 
273
+			.plain-text {
274
+				padding: 1em 2em 1em 2em;
275
+			}
276
+
273 277
 			.code-view {
274 278
 				* {
275 279
 					font-size: 12px;

+ 3 - 2
routers/repo/view.go

@@ -93,10 +93,11 @@ func renderDirectory(ctx *context.Context, treeLink string) {
93 93
 		if isTextFile {
94 94
 			d, _ := ioutil.ReadAll(dataRc)
95 95
 			buf = append(buf, d...)
96
-			ctx.Data["IsRenderedHTML"] = true
97 96
 			if markup.Type(readmeFile.Name()) != "" {
97
+				ctx.Data["IsMarkup"] = true
98 98
 				ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()))
99 99
 			} else {
100
+				ctx.Data["IsRenderedHTML"] = true
100 101
 				ctx.Data["FileContent"] = string(bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1))
101 102
 			}
102 103
 		}
@@ -194,7 +195,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
194 195
 		readmeExist := markup.IsReadmeFile(blob.Name())
195 196
 		ctx.Data["ReadmeExist"] = readmeExist
196 197
 		if markup.Type(blob.Name()) != "" {
197
-			ctx.Data["IsRenderedHTML"] = true
198
+			ctx.Data["IsMarkup"] = true
198 199
 			ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
199 200
 		} else if readmeExist {
200 201
 			ctx.Data["IsRenderedHTML"] = true

+ 4 - 2
templates/repo/view_file.tmpl

@@ -36,9 +36,11 @@
36 36
 		{{end}}
37 37
 	</h4>
38 38
 	<div class="ui attached table segment">
39
-		<div class="file-view {{if .IsRenderedHTML}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji">
40
-			{{if .IsRenderedHTML}}
39
+		<div class="file-view {{if .IsMarkup}}markdown{{else if .IsRenderedHTML}}plain-text{{else if .IsTextFile}}code-view{{end}} has-emoji">
40
+			{{if .IsMarkup}}
41 41
 				{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
42
+			{{else if .IsRenderedHTML}}
43
+				<pre>{{if .FileContent}}{{.FileContent | Str2html}}{{end}}</pre>
42 44
 			{{else if not .IsTextFile}}
43 45
 				<div class="view-raw ui center">
44 46
 					{{if .IsImageFile}}