mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-01 09:51:39 -05:00
c504461b66
Resolve all cases for `unused parameter` and `unnecessary type arguments` Related: #30729 --------- Co-authored-by: Giteabot <teabot@gitea.io> (cherry picked from commit e80466f7349164ce4cf3c07bdac30d736d20f035) Conflicts: modules/markup/markdown/transform_codespan.go modules/setting/incoming_email.go routers/api/v1/admin/user_badge.go routers/private/hook_pre_receive.go tests/integration/repo_search_test.go resolved by discarding the change, this is linting only and for the sake of avoiding future conflicts
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package markdown
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"code.gitea.io/gitea/modules/markup"
|
|
|
|
"github.com/yuin/goldmark/ast"
|
|
east "github.com/yuin/goldmark/extension/ast"
|
|
"github.com/yuin/goldmark/renderer/html"
|
|
"github.com/yuin/goldmark/util"
|
|
)
|
|
|
|
func (r *HTMLRenderer) renderTaskCheckBoxListItem(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
n := node.(*TaskCheckBoxListItem)
|
|
if entering {
|
|
if n.Attributes() != nil {
|
|
_, _ = w.WriteString("<li")
|
|
html.RenderAttributes(w, n, html.ListItemAttributeFilter)
|
|
_ = w.WriteByte('>')
|
|
} else {
|
|
_, _ = w.WriteString("<li>")
|
|
}
|
|
fmt.Fprintf(w, `<input type="checkbox" disabled="" data-source-position="%d"`, n.SourcePosition)
|
|
if n.IsChecked {
|
|
_, _ = w.WriteString(` checked=""`)
|
|
}
|
|
if r.XHTML {
|
|
_, _ = w.WriteString(` />`)
|
|
} else {
|
|
_ = w.WriteByte('>')
|
|
}
|
|
fc := n.FirstChild()
|
|
if fc != nil {
|
|
if _, ok := fc.(*ast.TextBlock); !ok {
|
|
_ = w.WriteByte('\n')
|
|
}
|
|
}
|
|
} else {
|
|
_, _ = w.WriteString("</li>\n")
|
|
}
|
|
return ast.WalkContinue, nil
|
|
}
|
|
|
|
func (r *HTMLRenderer) renderTaskCheckBox(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
return ast.WalkContinue, nil
|
|
}
|
|
|
|
func (g *ASTTransformer) transformList(_ *markup.RenderContext, v *ast.List, rc *RenderConfig) {
|
|
if v.HasChildren() {
|
|
children := make([]ast.Node, 0, v.ChildCount())
|
|
child := v.FirstChild()
|
|
for child != nil {
|
|
children = append(children, child)
|
|
child = child.NextSibling()
|
|
}
|
|
v.RemoveChildren(v)
|
|
|
|
for _, child := range children {
|
|
listItem := child.(*ast.ListItem)
|
|
if !child.HasChildren() || !child.FirstChild().HasChildren() {
|
|
v.AppendChild(v, child)
|
|
continue
|
|
}
|
|
taskCheckBox, ok := child.FirstChild().FirstChild().(*east.TaskCheckBox)
|
|
if !ok {
|
|
v.AppendChild(v, child)
|
|
continue
|
|
}
|
|
newChild := NewTaskCheckBoxListItem(listItem)
|
|
newChild.IsChecked = taskCheckBox.IsChecked
|
|
newChild.SetAttributeString("class", []byte("task-list-item"))
|
|
segments := newChild.FirstChild().Lines()
|
|
if segments.Len() > 0 {
|
|
segment := segments.At(0)
|
|
newChild.SourcePosition = rc.metaLength + segment.Start
|
|
}
|
|
v.AppendChild(v, newChild)
|
|
}
|
|
}
|
|
g.applyElementDir(v)
|
|
}
|