mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-16 01:43:24 +09:00
enhance: truncate but show long lines in diffs (#39279)
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
wxiaoguang
parent
da37b7916b
commit
1e13badb39
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user