summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2017-06-10 17:20:25 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2017-06-10 23:20:25 +0800
commitf2fcd9dcd834b611d2f321829e814a741054c4ea (patch)
treebf1cb86de7ea1c4a1b938a2b98ef7b36cc46b959
parent446a41d595c2a3477aa55b8e78e625bcdff42eb6 (diff)
downloadgitea-f2fcd9dcd834b611d2f321829e814a741054c4ea.tar.gz
gitea-f2fcd9dcd834b611d2f321829e814a741054c4ea.zip
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
-rw-r--r--public/css/index.css2
-rw-r--r--public/less/_repository.less2
-rw-r--r--routers/repo/view.go6
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(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, gotemplate.HTMLEscapeString(line)) + "\n")
+ line = gotemplate.HTMLEscapeString(line)
+ if index != len(lines)-1 {
+ line += "\n"
+ }
+ output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, line))
}
ctx.Data["FileContent"] = gotemplate.HTML(output.String())