enhance: truncate but show long lines in diffs (#39279)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Sergio Benitez
2026-09-12 11:56:25 +00:00
committed by GitHub
co-authored by wxiaoguang
parent da37b7916b
commit 1e13badb39
13 changed files with 430 additions and 222 deletions
+12 -5
View File
@@ -8,6 +8,7 @@ import (
"io"
"strings"
"gitea.dev/modules/htmlutil"
"gitea.dev/modules/setting"
"gitea.dev/modules/translation"
)
@@ -27,13 +28,19 @@ func EscapeOptionsForView() EscapeOptions {
}
}
func EscapeControlHTMLTo(html template.HTML, locale translation.Locale, w htmlutil.HTMLWriter, opts ...EscapeOptions) *EscapeStatus {
if !setting.UI.AmbiguousUnicodeDetection {
w.WriteHTML(html)
return &EscapeStatus{}
}
escaped, _ := EscapeControlReader(strings.NewReader(string(html)), w.OriginWriter(), locale, opts...)
return escaped
}
// EscapeControlHTML escapes the Unicode control sequences in a provided html document
func EscapeControlHTML(html template.HTML, locale translation.Locale, opts ...EscapeOptions) (escaped *EscapeStatus, output template.HTML) {
if !setting.UI.AmbiguousUnicodeDetection {
return &EscapeStatus{}, html
}
sb := &strings.Builder{}
escaped, _ = EscapeControlReader(strings.NewReader(string(html)), sb, locale, opts...) // err has been handled in EscapeControlReader
sb, w := htmlutil.NewHTMLStringWriter()
escaped = EscapeControlHTMLTo(html, locale, w, opts...)
return escaped, template.HTML(sb.String())
}