mirror of
1
Fork 0

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

View File

@ -32,7 +32,7 @@ const (
type ProcessorHelper struct {
IsUsernameMentionable func(ctx context.Context, username string) bool
GetRepoFileBlob func(ctx context.Context, ownerName, repoName, commitSha, filePath string, language *string) (*git.Blob, error)
GetRepoFileBlob func(ctx context.Context, ownerName, repoName, commitSha, filePath string, language *string) (*git.Blob, error)
ElementDir string // the direction of the elements, eg: "ltr", "rtl", "auto", default to no direction attribute
}

View File

@ -86,25 +86,6 @@ func ProcessorHelper() *markup.ProcessorHelper {
}
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*/
},
}
}