Fix linting issues
This commit is contained in:
parent
d789d33229
commit
8218e80bfc
2 changed files with 14 additions and 12 deletions
|
@ -9,16 +9,15 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/charset"
|
"code.gitea.io/gitea/modules/charset"
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/translation"
|
"code.gitea.io/gitea/modules/translation"
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
"golang.org/x/net/html/atom"
|
"golang.org/x/net/html/atom"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// filePreviewPattern matches "http://domain/org/repo/src/commit/COMMIT/filepath#L1-L2"
|
// filePreviewPattern matches "http://domain/org/repo/src/commit/COMMIT/filepath#L1-L2"
|
||||||
filePreviewPattern = regexp.MustCompile(`https?://((?:\S+/){3})src/commit/([0-9a-f]{4,64})/(\S+)#(L\d+(?:-L\d+)?)`)
|
var filePreviewPattern = regexp.MustCompile(`https?://((?:\S+/){3})src/commit/([0-9a-f]{4,64})/(\S+)#(L\d+(?:-L\d+)?)`)
|
||||||
)
|
|
||||||
|
|
||||||
type FilePreview struct {
|
type FilePreview struct {
|
||||||
fileContent []template.HTML
|
fileContent []template.HTML
|
||||||
|
@ -82,7 +81,10 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
|
||||||
lineCount := len(fileContent)
|
lineCount := len(fileContent)
|
||||||
|
|
||||||
commitLinkBuffer := new(bytes.Buffer)
|
commitLinkBuffer := new(bytes.Buffer)
|
||||||
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"))
|
||||||
|
if err != nil {
|
||||||
|
log.Error("failed to render commitLink: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if len(lineSpecs) == 1 {
|
if len(lineSpecs) == 1 {
|
||||||
line, _ := strconv.Atoi(strings.TrimPrefix(lineSpecs[0], "L"))
|
line, _ := strconv.Atoi(strings.TrimPrefix(lineSpecs[0], "L"))
|
||||||
|
@ -117,7 +119,7 @@ func NewFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
|
||||||
return preview
|
return preview
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *FilePreview) CreateHtml(locale translation.Locale) *html.Node {
|
func (p *FilePreview) CreateHTML(locale translation.Locale) *html.Node {
|
||||||
table := &html.Node{
|
table := &html.Node{
|
||||||
Type: html.ElementNode,
|
Type: html.ElementNode,
|
||||||
Data: atom.Table.String(),
|
Data: atom.Table.String(),
|
||||||
|
@ -257,13 +259,13 @@ func (p *FilePreview) CreateHtml(locale translation.Locale) *html.Node {
|
||||||
})
|
})
|
||||||
header.AppendChild(psubtitle)
|
header.AppendChild(psubtitle)
|
||||||
|
|
||||||
preview_node := &html.Node{
|
node := &html.Node{
|
||||||
Type: html.ElementNode,
|
Type: html.ElementNode,
|
||||||
Data: atom.Div.String(),
|
Data: atom.Div.String(),
|
||||||
Attr: []html.Attribute{{Key: "class", Val: "file-preview-box"}},
|
Attr: []html.Attribute{{Key: "class", Val: "file-preview-box"}},
|
||||||
}
|
}
|
||||||
preview_node.AppendChild(header)
|
node.AppendChild(header)
|
||||||
preview_node.AppendChild(twrapper)
|
node.AppendChild(twrapper)
|
||||||
|
|
||||||
return preview_node
|
return node
|
||||||
}
|
}
|
||||||
|
|
|
@ -1075,7 +1075,7 @@ func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
preview_node := preview.CreateHtml(locale)
|
previewNode := preview.CreateHTML(locale)
|
||||||
|
|
||||||
// Specialized version of replaceContent, so the parent paragraph element is not destroyed from our div
|
// Specialized version of replaceContent, so the parent paragraph element is not destroyed from our div
|
||||||
before := node.Data[:preview.start]
|
before := node.Data[:preview.start]
|
||||||
|
@ -1086,7 +1086,7 @@ func filePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
|
||||||
Type: html.RawNode,
|
Type: html.RawNode,
|
||||||
Data: "</p>",
|
Data: "</p>",
|
||||||
}, nextSibling)
|
}, nextSibling)
|
||||||
node.Parent.InsertBefore(preview_node, nextSibling)
|
node.Parent.InsertBefore(previewNode, nextSibling)
|
||||||
node.Parent.InsertBefore(&html.Node{
|
node.Parent.InsertBefore(&html.Node{
|
||||||
Type: html.RawNode,
|
Type: html.RawNode,
|
||||||
Data: "<p>" + after,
|
Data: "<p>" + after,
|
||||||
|
|
Loading…
Reference in a new issue