From 62719cdd2d7e62cd21f4bfcf8eb9ded37128159a Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 4 Nov 2020 08:14:07 +0100 Subject: [PATCH] Fix whitespace rendering in diff (#13415) - Introduce new .code-inner class that sets the CSS attributes on rendered code lines like view,blame and diff. - Rename .wrap class to .word-break to reflect what it actually does - Remove .raw which was only used on webhook page - Set white-space: pre-wrap except on blame where it can break the layout Fixes: https://github.com/go-gitea/gitea/issues/13406 --- routers/repo/blame.go | 1 + templates/repo/blame.tmpl | 2 +- templates/repo/diff/blob_excerpt.tmpl | 8 +-- templates/repo/diff/box.tmpl | 6 +-- templates/repo/diff/section_unified.tmpl | 4 +- templates/repo/settings/webhook/history.tmpl | 8 +-- templates/repo/view_file.tmpl | 2 +- templates/repo/wiki/revision.tmpl | 2 +- templates/user/profile.tmpl | 4 +- web_src/less/_base.less | 52 +++++--------------- web_src/less/_repository.less | 11 +++++ web_src/less/helpers.less | 3 ++ 12 files changed, 45 insertions(+), 58 deletions(-) diff --git a/routers/repo/blame.go b/routers/repo/blame.go index 69becc50d..812c55ea4 100644 --- a/routers/repo/blame.go +++ b/routers/repo/blame.go @@ -237,6 +237,7 @@ func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames m } fileName := fmt.Sprintf("%v", ctx.Data["FileName"]) line = highlight.Code(fileName, line) + line = `` + line + `` if len(part.Lines)-1 == index && len(blameParts)-1 != pi { codeLines.WriteString(fmt.Sprintf(`
  • %s
  • `, i, i, line)) } else { diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index 5d9a17101..5dd93d3d4 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -26,7 +26,7 @@ {{.BlameCommitInfo}} {{.BlameLineNums}} -
      {{.BlameContent}}
    +
      {{.BlameContent}}
    diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl index 6bcb14406..2543756d4 100644 --- a/templates/repo/diff/blob_excerpt.tmpl +++ b/templates/repo/diff/blob_excerpt.tmpl @@ -19,14 +19,14 @@ {{end}} - {{$.section.GetComputedInlineDiffFor $line}} + {{$.section.GetComputedInlineDiffFor $line}} {{else}} {{if $line.LeftIdx}}{{end}} - {{if $line.LeftIdx}}{{$.section.GetComputedInlineDiffFor $line}}{{end}} + {{if $line.LeftIdx}}{{$.section.GetComputedInlineDiffFor $line}}{{end}} {{if $line.RightIdx}}{{end}} - {{if $line.RightIdx}}{{$.section.GetComputedInlineDiffFor $line}}{{end}} + {{if $line.RightIdx}}{{$.section.GetComputedInlineDiffFor $line}}{{end}} {{end}} {{end}} @@ -56,7 +56,7 @@ {{end}} - {{$.section.GetComputedInlineDiffFor $line}} + {{$.section.GetComputedInlineDiffFor $line}} {{end}} {{end}} diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index c2a7ade64..e45f3db59 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -154,14 +154,14 @@ {{end}} - {{$section.GetComputedInlineDiffFor $line}} + {{$section.GetComputedInlineDiffFor $line}} {{else}} {{if $line.LeftIdx}}{{end}} - {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}{{end}}{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} + {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}{{end}}{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} {{if $line.RightIdx}}{{end}} - {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}{{end}}{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} + {{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}{{end}}{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}} {{end}} {{if gt (len $line.Comments) 0}} diff --git a/templates/repo/diff/section_unified.tmpl b/templates/repo/diff/section_unified.tmpl index 3b24cd453..129a14c1b 100644 --- a/templates/repo/diff/section_unified.tmpl +++ b/templates/repo/diff/section_unified.tmpl @@ -27,9 +27,9 @@ {{end}} {{if eq .GetType 4}} - {{$section.GetComputedInlineDiffFor $line}} + {{$section.GetComputedInlineDiffFor $line}} {{else}} - {{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles}}{{end}}{{$section.GetComputedInlineDiffFor $line}} + {{if and $.root.SignedUserID $line.CanComment $.root.PageIsPullFiles}}{{end}}{{$section.GetComputedInlineDiffFor $line}} {{end}} {{if gt (len $line.Comments) 0}} diff --git a/templates/repo/settings/webhook/history.tmpl b/templates/repo/settings/webhook/history.tmpl index 6499b9311..cf4884531 100644 --- a/templates/repo/settings/webhook/history.tmpl +++ b/templates/repo/settings/webhook/history.tmpl @@ -44,12 +44,12 @@
    {{if .RequestInfo}}
    {{$.i18n.Tr "repo.settings.webhook.headers"}}
    -
    Request URL: {{.URL}}
    +								
    Request URL: {{.URL}}
     Request method: {{if .HTTPMethod}}{{.HTTPMethod}}{{else}}POST{{end}}
     {{ range $key, $val := .RequestInfo.Headers }}{{$key}}: {{$val}}
     {{end}}
    {{$.i18n.Tr "repo.settings.webhook.payload"}}
    -
    {{.PayloadContent}}
    +
    {{.PayloadContent}}
    {{else}} N/A {{end}} @@ -57,10 +57,10 @@
    {{if .ResponseInfo}}
    {{$.i18n.Tr "repo.settings.webhook.headers"}}
    -
    {{ range $key, $val := .ResponseInfo.Headers }}{{$key}}: {{$val}}
    +								
    {{ range $key, $val := .ResponseInfo.Headers }}{{$key}}: {{$val}}
     {{end}}
    {{$.i18n.Tr "repo.settings.webhook.body"}}
    -
    {{.ResponseInfo.Body}}
    +
    {{.ResponseInfo.Body}}
    {{else}} N/A {{end}} diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index a8d60bd96..a849fa1f8 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -99,7 +99,7 @@ - {{$code | Safe}} + {{$code | Safe}} {{end}} diff --git a/templates/repo/wiki/revision.tmpl b/templates/repo/wiki/revision.tmpl index da07901bf..5f1fa08a5 100644 --- a/templates/repo/wiki/revision.tmpl +++ b/templates/repo/wiki/revision.tmpl @@ -31,7 +31,7 @@
    {{.revision}} {{svg "octicon-home"}} {{$title}} -
    +
    {{$timeSince := TimeSince .Author.When $.Lang}} {{.i18n.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince | Safe}}
    diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 9deadd921..3a3192a82 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -13,11 +13,11 @@ {{end}} -
    +
    {{if .Owner.FullName}}{{.Owner.FullName}}{{end}} {{.Owner.Name}}
    -
    +
      {{if .Owner.Location}}
    • {{svg "octicon-location"}} {{.Owner.Location}}
    • diff --git a/web_src/less/_base.less b/web_src/less/_base.less index 9a22e075f..09e796ac5 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -177,42 +177,6 @@ a:hover, color: var(--color-primary-dark-2); } -.rounded { - border-radius: var(--border-radius) !important; -} - -.wrap { - word-wrap: break-word; - word-break: break-all; -} - -.mono { - font-family: var(--fonts-monospace); -} - -pre, -code { - font: 12px var(--fonts-monospace); - - &.raw { - padding: 7px 12px; - margin: 10px 0; - background-color: #f8f8f8; - border: 1px solid #dddddd; - border-radius: 3px; - font-size: 13px; - line-height: 1.5; - overflow: auto; - } - - &.wrap { - white-space: pre-wrap; - word-break: break-all; - overflow-wrap: break-word; - word-wrap: break-word; - } -} - .dont-break-out { overflow-wrap: break-word; word-wrap: break-word; @@ -1137,10 +1101,6 @@ i.icon.centerlock { padding-left: 5px; } -.lines-code code { - white-space: pre; -} - .lines-code.active, .lines-code .active { background: #fffbdd !important; @@ -1155,6 +1115,18 @@ i.icon.centerlock { padding: 0 !important; } +.code-inner { + font: 12px var(--fonts-monospace); + white-space: pre-wrap; + word-break: break-all; + overflow-wrap: break-word; + word-wrap: break-word; +} + +.blame .code-inner { + white-space: pre; +} + .lines-commit { vertical-align: top; color: #999999; diff --git a/web_src/less/_repository.less b/web_src/less/_repository.less index 45abae917..72b500d4a 100644 --- a/web_src/less/_repository.less +++ b/web_src/less/_repository.less @@ -3239,6 +3239,17 @@ td.blob-excerpt { padding-left: 8px; } +.webhook-info { + padding: 7px 12px; + margin: 10px 0; + background-color: #f8f8f8; + border: 1px solid #dddddd; + border-radius: 3px; + font-size: 13px; + line-height: 1.5; + overflow: auto; +} + .title_wip_desc { margin-top: 1em; } diff --git a/web_src/less/helpers.less b/web_src/less/helpers.less index fff866c66..b62ce3494 100644 --- a/web_src/less/helpers.less +++ b/web_src/less/helpers.less @@ -4,6 +4,9 @@ .js { justify-content: flex-start; } .je { justify-content: flex-end; } .sb { justify-content: space-between; } +.mono { font-family: var(--fonts-monospace); } +.rounded { border-radius: var(--border-radius) !important; } +.word-break { word-wrap: break-word; word-break: break-all; } .m-0 { margin: 0 !important; } .m-1 { margin: .125rem !important; }