From f2fcd9dcd834b611d2f321829e814a741054c4ea Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 10 Jun 2017 17:20:25 +0200 Subject: [PATCH] Support CRLF when splitting code lines for display (#1862) * Support CRLF when splitting code lines for display * refactor, fix mixed match * fmt * split on both LF and CRLF, use raw literals in regexes * simplify --- public/css/index.css | 2 +- public/less/_repository.less | 2 +- routers/repo/view.go | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/public/css/index.css b/public/css/index.css index 0d6112a168..35e56413b1 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -1435,7 +1435,7 @@ footer .ui.language .menu { .repository.file.list #file-content .code-view .lines-code ol li, .repository.file.list #file-content .code-view .lines-num .hljs li, .repository.file.list #file-content .code-view .lines-code .hljs li { - display: inline-block; + display: block; width: 100%; } .repository.file.list #file-content .code-view .lines-num pre li.active, diff --git a/public/less/_repository.less b/public/less/_repository.less index 56249f3a9a..c6f4527634 100644 --- a/public/less/_repository.less +++ b/public/less/_repository.less @@ -296,7 +296,7 @@ margin: 0; padding: 0 !important; li { - display: inline-block; + display: block; width: 100%; &.active { background: #ffffdd; diff --git a/routers/repo/view.go b/routers/repo/view.go index a3c42a0fdd..84e5ba85ce 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -212,7 +212,11 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st var output bytes.Buffer lines := strings.Split(fileContent, "\n") for index, line := range lines { - output.WriteString(fmt.Sprintf(`
  • %s
  • `, index+1, index+1, gotemplate.HTMLEscapeString(line)) + "\n") + line = gotemplate.HTMLEscapeString(line) + if index != len(lines)-1 { + line += "\n" + } + output.WriteString(fmt.Sprintf(`
  • %s
  • `, index+1, index+1, line)) } ctx.Data["FileContent"] = gotemplate.HTML(output.String())