-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Render plain text README.txt monospaced #2721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Jonas Franz <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #2721 +/- ##
=======================================
Coverage 26.96% 26.96%
=======================================
Files 87 87
Lines 17297 17297
=======================================
Hits 4664 4664
Misses 11953 11953
Partials 680 680 Continue to review full report at Codecov.
|
Signed-off-by: Jonas Franz <[email protected]>
This will break markdown rendering. |
@Morlinest Why? It is not used when markup is rendered. (See acaf4b3) |
@JonasFranzDEV I was checking your first version (commit). Will look at it again. |
routers/repo/view.go
Outdated
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) | ||
} else if readmeExist { | ||
ctx.Data["IsRenderedHTML"] = true | ||
ctx.Data["IsMarkup"] = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep only ctx.Data["IsMarkup"] = true
templates/repo/view_file.tmpl
Outdated
@@ -38,7 +38,11 @@ | |||
<div class="ui attached table segment"> | |||
<div class="file-view {{if .IsRenderedHTML}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji"> | |||
{{if .IsRenderedHTML}} | |||
<pre>{{if .FileContent}}{{.FileContent | Str2html}}{{end}}</pre> | |||
{{if not .IsMarkup}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch order, test for {{if .IsMarkup}}
Signed-off-by: Jonas Franz <[email protected]>
templates/repo/view_file.tmpl
Outdated
{{if .IsMarkup}} | ||
{{if .FileContent}}{{.FileContent | Str2html}}{{end}} | ||
{{else}} | ||
<pre>{{if .FileContent}}{{.FileContent | Str2html}}{{end}}</pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is rly Str2html
needed here?
<pre>
should be inside {{if .FileContent}}
block.
Edit: Probably it's safe to always use Str2html
routers/repo/view.go
Outdated
@@ -195,6 +195,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st | |||
ctx.Data["ReadmeExist"] = readmeExist | |||
if markup.Type(blob.Name()) != "" { | |||
ctx.Data["IsRenderedHTML"] = true | |||
ctx.Data["IsMarkup"] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please look for other places with markup.Type
check. I think it (ctx.Data["IsMarkup"] = true
) should be added also there (I found https://github.com/JonasFranzDEV/gitea/blob/5aca5a8a3d618630d10272445badcbea5381683f/routers/repo/view.go#L97).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
templates/repo/view_file.tmpl
Outdated
@@ -38,7 +38,11 @@ | |||
<div class="ui attached table segment"> | |||
<div class="file-view {{if .IsRenderedHTML}}markdown{{else if .IsTextFile}}code-view{{end}} has-emoji"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fine in all, try cleaning cache (also did you do make generate-stylesheets
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also did you do make generate-stylesheets?
Yes
routers/repo/view.go
Outdated
@@ -195,6 +195,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st | |||
ctx.Data["ReadmeExist"] = readmeExist | |||
if markup.Type(blob.Name()) != "" { | |||
ctx.Data["IsRenderedHTML"] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx.Data["IsRenderedHTML"] = true
can be removed (check other places, same as markup.Type
) if ctx.Data["IsMarkup"] = true
is set, then you can remove nested if
from template and use else if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where should I remove the if
in template? (Could you provide a Line?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Jonas Franz <[email protected]>
public/less/_repository.less
Outdated
@@ -270,6 +270,10 @@ | |||
} | |||
} | |||
|
|||
.plain-text { | |||
padding: 1em 2em 1em 2em; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something looks wrong with spacing
Fixed spacing at repository.less Signed-off-by: Jonas Franz <[email protected]>
routers/repo/view.go
Outdated
@@ -95,6 +95,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { | |||
buf = append(buf, d...) | |||
ctx.Data["IsRenderedHTML"] = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this line to line 101
Signed-off-by: Jonas Franz <[email protected]>
LGTM |
{{if .FileContent}}{{.FileContent | Str2html}}{{end}} | ||
{{else if .IsRenderedHTML}} | ||
<pre>{{if .FileContent}}{{.FileContent | Str2html}}{{end}}</pre> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move <pre>
inside {{if .FileContent}}
block. Don't need to render empty tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Morlinest it is better to render it because of margins as css is accounted for plain-text to have pre inside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks OK then
LGTM |
Fixes #2718
Will add
<pre>TEXT</pre>
at the readme page.Screenshot