Skip to content

Commit f2fcd9d

Browse files
silverwindlunny
authored andcommitted
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
1 parent 446a41d commit f2fcd9d

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

public/css/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ footer .ui.language .menu {
14351435
.repository.file.list #file-content .code-view .lines-code ol li,
14361436
.repository.file.list #file-content .code-view .lines-num .hljs li,
14371437
.repository.file.list #file-content .code-view .lines-code .hljs li {
1438-
display: inline-block;
1438+
display: block;
14391439
width: 100%;
14401440
}
14411441
.repository.file.list #file-content .code-view .lines-num pre li.active,

public/less/_repository.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@
296296
margin: 0;
297297
padding: 0 !important;
298298
li {
299-
display: inline-block;
299+
display: block;
300300
width: 100%;
301301
&.active {
302302
background: #ffffdd;

routers/repo/view.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
212212
var output bytes.Buffer
213213
lines := strings.Split(fileContent, "\n")
214214
for index, line := range lines {
215-
output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, gotemplate.HTMLEscapeString(line)) + "\n")
215+
line = gotemplate.HTMLEscapeString(line)
216+
if index != len(lines)-1 {
217+
line += "\n"
218+
}
219+
output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, line))
216220
}
217221
ctx.Data["FileContent"] = gotemplate.HTML(output.String())
218222

0 commit comments

Comments
 (0)