Fix formating & remove commented out code

This commit is contained in:
Mai-Lapyst 2024-03-27 18:36:12 +01:00
parent 4c7cb0a5d2
commit 7e0014dd13
No known key found for this signature in database
GPG key ID: F88D929C09E239F8
3 changed files with 5 additions and 36 deletions

View file

@ -37,7 +37,7 @@ type FilePreview struct {
} }
func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Locale) *FilePreview { func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Locale) *FilePreview {
if (setting.FilePreviewMaxLines == 0) { if setting.FilePreviewMaxLines == 0 {
// Feature is disabled // Feature is disabled
return nil return nil
} }
@ -84,7 +84,6 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
} }
lineSpecs := strings.Split(hash, "-") lineSpecs := strings.Split(hash, "-")
// lineCount := len(fileContent)
commitLinkBuffer := new(bytes.Buffer) commitLinkBuffer := new(bytes.Buffer)
err = html.Render(commitLinkBuffer, createLink(node.Data[m[0]:m[5]], commitSha[0:7], "text black")) err = html.Render(commitLinkBuffer, createLink(node.Data[m[0]:m[5]], commitSha[0:7], "text black"))
@ -97,11 +96,6 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
if len(lineSpecs) == 1 { if len(lineSpecs) == 1 {
startLine, _ = strconv.Atoi(strings.TrimPrefix(lineSpecs[0], "L")) startLine, _ = strconv.Atoi(strings.TrimPrefix(lineSpecs[0], "L"))
endLine = startLine endLine = startLine
// if line < 1 || line > lineCount {
// return nil
// }
// preview.fileContent = fileContent[line-1 : line]
preview.subTitle = locale.Tr( preview.subTitle = locale.Tr(
"markup.filepreview.line", startLine, "markup.filepreview.line", startLine,
template.HTML(commitLinkBuffer.String()), template.HTML(commitLinkBuffer.String()),
@ -111,12 +105,6 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
} else { } else {
startLine, _ = strconv.Atoi(strings.TrimPrefix(lineSpecs[0], "L")) startLine, _ = strconv.Atoi(strings.TrimPrefix(lineSpecs[0], "L"))
endLine, _ = strconv.Atoi(strings.TrimPrefix(lineSpecs[1], "L")) endLine, _ = strconv.Atoi(strings.TrimPrefix(lineSpecs[1], "L"))
// if startLine < 1 || endLine < 1 || startLine > lineCount || endLine > lineCount || endLine < startLine {
// return nil
// }
// preview.fileContent = fileContent[startLine-1 : endLine]
preview.subTitle = locale.Tr( preview.subTitle = locale.Tr(
"markup.filepreview.lines", startLine, endLine, "markup.filepreview.lines", startLine, endLine,
template.HTML(commitLinkBuffer.String()), template.HTML(commitLinkBuffer.String()),
@ -156,7 +144,7 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
for i := 0; i < lineCount; i++ { for i := 0; i < lineCount; i++ {
buf, err := reader.ReadBytes('\n') buf, err := reader.ReadBytes('\n')
if err != nil { if err != nil {
break; break
} }
lineBuffer.Write(buf) lineBuffer.Write(buf)
} }
@ -316,7 +304,7 @@ func (p *FilePreview) CreateHTML(locale translation.Locale) *html.Node {
} }
node.AppendChild(header) node.AppendChild(header)
if (p.isTruncated) { if p.isTruncated {
warning := &html.Node{ warning := &html.Node{
Type: html.ElementNode, Type: html.ElementNode,
Data: atom.Div.String(), Data: atom.Div.String(),

View file

@ -86,25 +86,6 @@ func ProcessorHelper() *markup.ProcessorHelper {
} }
return blob, nil return blob, nil
/*dataRc, err := blob.DataAsync()
if err != nil {
return nil, err
}
defer dataRc.Close()
buf, err := io.ReadAll(dataRc)
if err != nil {
log.Error("failed to completly read blob for %-v:%s. Error: %v", repo, filePath, err)
}
fileContent, _, err := highlight.File(blob.Name(), language, buf)
if err != nil {
log.Error("highlight.File failed, fallback to plain text: %v", err)
fileContent = highlight.PlainText(buf)
}
return fileContent, nil*/
}, },
} }
} }