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
@@ -6,13 +6,15 @@ package markup
import (
"strings"
"code.gitea.io/gitea/modules/markup/common"
"golang.org/x/net/html"
)
func isAnchorIDUserContent(s string) bool {
// blackfridayExtRegex is for blackfriday extensions create IDs like fn:user-content-footnote
// old logic: blackfridayExtRegex = regexp.MustCompile(`[^:]*:user-content-`)
return strings.HasPrefix(s, "user-content-") || strings.Contains(s, ":user-content-")
return strings.HasPrefix(s, "user-content-") || strings.Contains(s, ":user-content-") || isAnchorIDFootnote(s)
}
func isAnchorIDFootnote(s string) bool {
@@ -23,16 +25,80 @@ func isAnchorHrefFootnote(s string) bool {
return strings.HasPrefix(s, "#fnref:user-content-") || strings.HasPrefix(s, "#fn:user-content-")
}
func processNodeAttrID(node *html.Node) {
// isHeadingTag returns true if the node is a heading tag (h1-h6)
func isHeadingTag(node *html.Node) bool {
return node.Type == html.ElementNode &&
len(node.Data) == 2 &&
node.Data[0] == 'h' &&
node.Data[1] >= '1' && node.Data[1] <= '6'
}
// getNodeText extracts the text content from a node and its children
func getNodeText(node *html.Node, cached **string) string {
if *cached != nil {
return **cached
}
var text strings.Builder
var extractText func(*html.Node)
extractText = func(n *html.Node) {
if n.Type == html.TextNode {
text.WriteString(n.Data)
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
extractText(c)
}
}
extractText(node)
textStr := text.String()
*cached = &textStr
return textStr
}
func processNodeHeadingAndID(ctx *RenderContext, node *html.Node) {
// TODO: handle duplicate IDs, need to track existing IDs in the document
// Add user-content- to IDs and "#" links if they don't already have them,
// and convert the link href to a relative link to the host root
attrIDVal := ""
for idx, attr := range node.Attr {
if attr.Key == "id" {
if !isAnchorIDUserContent(attr.Val) {
node.Attr[idx].Val = "user-content-" + attr.Val
attrIDVal = attr.Val
if !isAnchorIDUserContent(attrIDVal) {
attrIDVal = "user-content-" + attrIDVal
node.Attr[idx].Val = attrIDVal
}
}
}
if !isHeadingTag(node) || !ctx.RenderOptions.EnableHeadingIDGeneration {
return
}
// For heading tags (h1-h6) without an id attribute, generate one from the text content.
// This ensures HTML headings like <h1>Title</h1> get proper permalink anchors
// matching the behavior of Markdown headings.
// Only enabled for repository files and wiki pages via EnableHeadingIDGeneration option.
var nodeTextCached *string
if attrIDVal == "" {
nodeText := getNodeText(node, &nodeTextCached)
if nodeText != "" {
// Use the same CleanValue function used by Markdown heading ID generation
attrIDVal = string(common.CleanValue([]byte(nodeText)))
if attrIDVal != "" {
attrIDVal = "user-content-" + attrIDVal
node.Attr = append(node.Attr, html.Attribute{Key: "id", Val: attrIDVal})
}
}
}
if ctx.TocShowInSection != "" {
nodeText := getNodeText(node, &nodeTextCached)
if nodeText != "" && attrIDVal != "" {
ctx.TocHeadingItems = append(ctx.TocHeadingItems, &TocHeadingItem{
HeadingLevel: int(node.Data[1] - '0'),
AnchorID: attrIDVal,
InnerText: nodeText,
})
}
}
}
func processFootnoteNode(ctx *RenderContext, node *html.Node) {