فهرست منبع

[GINR] Max line count with code highlighting

cgars 7 سال پیش
والد
کامیت
f6077c17a7
3فایلهای تغییر یافته به همراه8 افزوده شده و 2 حذف شده
  1. 2 0
      conf/app.ini
  2. 1 0
      pkg/setting/setting.go
  3. 5 2
      routes/repo/view.go

+ 2 - 0
conf/app.ini

@@ -440,6 +440,8 @@ FEED_MAX_COMMIT_NUM = 5
 THEME_COLOR_META_TAG = `#ff5343`
 THEME_COLOR_META_TAG = `#ff5343`
 ; Max size in bytes of files to be displayed (default is 8MB)
 ; Max size in bytes of files to be displayed (default is 8MB)
 MAX_DISPLAY_FILE_SIZE = 8388608
 MAX_DISPLAY_FILE_SIZE = 8388608
+; Max size in bytes of files to be highlighted (default is 8MB)
+MAX_LINE_HIGHLIGHT = 5000
 
 
 [ui.admin]
 [ui.admin]
 ; Number of users that are showed in one page
 ; Number of users that are showed in one page

+ 1 - 0
pkg/setting/setting.go

@@ -280,6 +280,7 @@ var (
 		FeedMaxCommitNum   int
 		FeedMaxCommitNum   int
 		ThemeColorMetaTag  string
 		ThemeColorMetaTag  string
 		MaxDisplayFileSize int64
 		MaxDisplayFileSize int64
+		MaxLineHighlight   int
 
 
 		Admin struct {
 		Admin struct {
 			UserPagingNum   int
 			UserPagingNum   int

+ 5 - 2
routes/repo/view.go

@@ -259,7 +259,6 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 			afp.Seek(0, 0)
 			afp.Seek(0, 0)
 			afp.Read(buf)
 			afp.Read(buf)
 		}
 		}
-
 		switch markup.Detect(blob.Name()) {
 		switch markup.Detect(blob.Name()) {
 		case markup.MARKDOWN:
 		case markup.MARKDOWN:
 			c.Data["IsMarkdown"] = true
 			c.Data["IsMarkdown"] = true
@@ -280,9 +279,13 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 			} else {
 			} else {
 				fileContent = content
 				fileContent = content
 			}
 			}
-
+			fileContent = string(buf)
+			log.Trace("Buffer Size is: %d", len(buf))
 			var output bytes.Buffer
 			var output bytes.Buffer
 			lines := strings.Split(fileContent, "\n")
 			lines := strings.Split(fileContent, "\n")
+			if len(lines) > setting.UI.MaxLineHighlight {
+				c.Data["HighlightClass"] = "nohighlight"
+			}
 			for index, line := range lines {
 			for index, line := range lines {
 				output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, gotemplate.HTMLEscapeString(strings.TrimRight(line, "\r"))) + "\n")
 				output.WriteString(fmt.Sprintf(`<li class="L%d" rel="L%d">%s</li>`, index+1, index+1, gotemplate.HTMLEscapeString(strings.TrimRight(line, "\r"))) + "\n")
 			}
 			}