summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorRory McNamara <psychomario@users.noreply.github.com>2016-08-09 20:35:20 +0100
committer无闻 <u@gogs.io>2016-08-09 12:35:20 -0700
commitc8b45ecc2762a9d64dbe83cafd68b137661448a5 (patch)
treedf16d7b1b41d3fcade098cfe550cc61955d048c6 /routers/repo
parent9e8a8867ea3b4c977b436951a28d84e0c2ad2e4b (diff)
downloadgitea-c8b45ecc2762a9d64dbe83cafd68b137661448a5.tar.gz
gitea-c8b45ecc2762a9d64dbe83cafd68b137661448a5.zip
Render the Code view on the server (minus syntax highlighting) (#2942)
* render code view server side * remove debug print * fix multiline selection bug * change string concatenation to bytes.Buffer for efficiency * Fix newlines added by previous for hljs * fix selection highlighting * make css changes in .less
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/view.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 7bcdc1293c..c13f57f426 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -5,11 +5,14 @@
package repo
import (
+ "fmt"
"bytes"
"io/ioutil"
"path"
"strings"
+ htmltemplate "html/template"
+
"github.com/Unknwon/paginater"
"github.com/gogits/git-module"
@@ -116,14 +119,27 @@ func Home(ctx *context.Context) {
if readmeExist {
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
} else {
+ filecontent := ""
if err, content := template.ToUtf8WithErr(buf); err != nil {
if err != nil {
log.Error(4, "Convert content encoding: %s", err)
}
- ctx.Data["FileContent"] = string(buf)
+ filecontent = string(buf)
} else {
- ctx.Data["FileContent"] = content
+ filecontent = content
+ }
+ 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, htmltemplate.HTMLEscapeString(line)) + "\n")
+ }
+ ctx.Data["FileContent"] = htmltemplate.HTML(output.String())
+
+ output.Reset()
+ for i := 0; i < len(lines); i++ {
+ output.WriteString(fmt.Sprintf(`<span id="L%d">%d</span>`, i+1, i+1))
}
+ ctx.Data["LineNums"] = htmltemplate.HTML(output.String())
}
}
}