feat: vendor gitea 1.16.2

This commit is contained in:
2026-06-02 08:36:01 +00:00
parent 247cd60f69
commit 54798b4615
2145 changed files with 162965 additions and 126447 deletions
+50 -2
View File
@@ -12,7 +12,9 @@ import (
"strings"
"sync"
"code.gitea.io/gitea/modules/htmlutil"
"code.gitea.io/gitea/modules/markup/common"
"code.gitea.io/gitea/modules/translation"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
@@ -60,7 +62,7 @@ var globalVars = sync.OnceValue(func() *globalVarsType {
v.shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`)
// anyHashPattern splits url containing SHA into parts
v.anyHashPattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{40,64})(/[-+~%./\w]+)?(\?[-+~%.\w&=]+)?(#[-+~%.\w]+)?`)
v.anyHashPattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{40,64})((\.\w+)*)(/[-+~%./\w]+)?(\?[-+~%.\w&=]+)?(#[-+~%.\w]+)?`)
// comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash"
v.comparePattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(\.\.\.?)([0-9a-f]{7,64})?(#[-+~_%.a-zA-Z0-9]+)?`)
@@ -234,6 +236,49 @@ func postProcessString(ctx *RenderContext, procs []processor, content string) (s
return buf.String(), nil
}
func RenderTocHeadingItems(ctx *RenderContext, nodeDetailsAttrs map[string]string, out io.Writer) {
locale, ok := ctx.Value(translation.ContextKey).(translation.Locale)
if !ok {
locale = translation.NewLocale("")
}
_, _ = htmlutil.HTMLPrintTag(out, "details", nodeDetailsAttrs)
_, _ = htmlutil.HTMLPrintf(out, "<summary>%s</summary>\n", locale.TrString("toc"))
baseLevel := 6
for _, header := range ctx.TocHeadingItems {
if header.HeadingLevel < baseLevel {
baseLevel = header.HeadingLevel
}
}
currentLevel := baseLevel
indent := []byte{' ', ' '}
_, _ = htmlutil.HTMLPrint(out, "<ul>\n")
for _, header := range ctx.TocHeadingItems {
for currentLevel < header.HeadingLevel {
_, _ = out.Write(indent)
_, _ = htmlutil.HTMLPrint(out, "<ul>\n")
indent = append(indent, ' ', ' ')
currentLevel++
}
for currentLevel > header.HeadingLevel {
indent = indent[:len(indent)-2]
_, _ = out.Write(indent)
_, _ = htmlutil.HTMLPrint(out, "</ul>\n")
currentLevel--
}
_, _ = out.Write(indent)
_, _ = htmlutil.HTMLPrintf(out, "<li><a href=\"#%s\">%s</a></li>\n", header.AnchorID, header.InnerText)
}
for currentLevel > baseLevel {
indent = indent[:len(indent)-2]
_, _ = out.Write(indent)
_, _ = htmlutil.HTMLPrint(out, "</ul>\n")
currentLevel--
}
_, _ = htmlutil.HTMLPrint(out, "</ul>\n</details>\n")
}
func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output io.Writer) error {
if !ctx.usedByRender && ctx.RenderHelper != nil {
defer ctx.RenderHelper.CleanUp()
@@ -284,6 +329,9 @@ func postProcess(ctx *RenderContext, procs []processor, input io.Reader, output
}
// Render everything to buf.
if ctx.TocShowInSection == TocShowInMain && len(ctx.TocHeadingItems) > 0 {
RenderTocHeadingItems(ctx, nil, output)
}
for _, node := range newNodes {
if err := html.Render(output, node); err != nil {
return fmt.Errorf("markup.postProcess: html.Render: %w", err)
@@ -314,7 +362,7 @@ func visitNode(ctx *RenderContext, procs []processor, node *html.Node) *html.Nod
return node.NextSibling
}
processNodeAttrID(node)
processNodeHeadingAndID(ctx, node)
processFootnoteNode(ctx, node) // FIXME: the footnote processing should be done in the "footnote.go" renderer directly
if isEmojiNode(node) {