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
@@ -5,7 +5,6 @@ package orgmode
import (
"fmt"
"html"
"html/template"
"io"
"strings"
@@ -17,7 +16,6 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/alecthomas/chroma/v2"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/niklasfasching/go-org/org"
)
@@ -33,20 +31,16 @@ var (
_ markup.PostProcessRenderer = (*renderer)(nil)
)
// Name implements markup.Renderer
func (renderer) Name() string {
return "orgmode"
}
// NeedPostProcess implements markup.PostProcessRenderer
func (renderer) NeedPostProcess() bool { return true }
// Extensions implements markup.Renderer
func (renderer) Extensions() []string {
return []string{".org"}
func (renderer) FileNamePatterns() []string {
return []string{"*.org"}
}
// SanitizerRules implements markup.Renderer
func (renderer) SanitizerRules() []setting.MarkupSanitizerRule {
return []setting.MarkupSanitizerRule{}
}
@@ -57,40 +51,20 @@ func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error
htmlWriter.HighlightCodeBlock = func(source, lang string, inline bool, params map[string]string) string {
defer func() {
if err := recover(); err != nil {
// catch the panic, log the error and return empty result
log.Error("Panic in HighlightCodeBlock: %v\n%s", err, log.Stack(2))
panic(err)
}
}()
w := &strings.Builder{}
lexer := lexers.Get(lang)
if lexer == nil && lang == "" {
lexer = lexers.Analyse(source)
if lexer == nil {
lexer = lexers.Fallback
}
lang = strings.ToLower(lexer.Config().Name)
}
lexer := highlight.DetectChromaLexerByFileName("", lang) // don't use content to detect, it is too slow
lexer = chroma.Coalesce(lexer)
sb := &strings.Builder{}
// include language-x class as part of commonmark spec
if err := ctx.RenderInternal.FormatWithSafeAttrs(w, `<pre><code class="chroma language-%s">`, lang); err != nil {
return ""
}
if lexer == nil {
if _, err := w.WriteString(html.EscapeString(source)); err != nil {
return ""
}
} else {
lexer = chroma.Coalesce(lexer)
if _, err := w.WriteString(string(highlight.CodeFromLexer(lexer, source))); err != nil {
return ""
}
}
if _, err := w.WriteString("</code></pre>"); err != nil {
return ""
}
return w.String()
_ = ctx.RenderInternal.FormatWithSafeAttrs(sb, `<pre><code class="chroma language-%s">`, strings.ToLower(lexer.Config().Name))
_, _ = sb.WriteString(string(highlight.RenderCodeByLexer(lexer, source)))
_, _ = sb.WriteString("</code></pre>")
return sb.String()
}
w := &orgWriter{rctx: ctx, HTMLWriter: htmlWriter}