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 13:56:25 +02:00
committed by GitHub
parent da37b7916b
commit 1e13badb39
13 changed files with 430 additions and 222 deletions
+7 -2
View File
@@ -93,7 +93,7 @@ type HTMLWriter interface {
OriginWriter() io.Writer
WriteString(s string) HTMLWriter
WriteHTML(s template.HTML) HTMLWriter
WriteFormat(fmt template.HTML, args ...any) HTMLWriter
WriteFormatf(fmt template.HTML, args ...any) HTMLWriter
Err() error
}
@@ -120,7 +120,7 @@ func (h *htmlWriter) WriteHTML(s template.HTML) HTMLWriter {
return h
}
func (h *htmlWriter) WriteFormat(fmt template.HTML, args ...any) HTMLWriter {
func (h *htmlWriter) WriteFormatf(fmt template.HTML, args ...any) HTMLWriter {
if _, err := HTMLPrintf(h.w, fmt, args...); err != nil {
h.errs = append(h.errs, err)
}
@@ -135,6 +135,11 @@ func NewHTMLWriter(w io.Writer) HTMLWriter {
return &htmlWriter{w: w}
}
func NewHTMLStringWriter() (*strings.Builder, HTMLWriter) {
sb := &strings.Builder{}
return sb, &htmlWriter{w: sb}
}
type HTMLBuilder struct {
sb strings.Builder
}
+1 -1
View File
@@ -34,7 +34,7 @@ func TestHTMLBuilder(t *testing.T) {
func TestHTMLWriter(t *testing.T) {
sb := new(strings.Builder)
w := NewHTMLWriter(sb)
w.WriteString("<").WriteHTML("<hr>").WriteFormat("<span>%s%s</span>", ">", EscapeString(">"))
w.WriteString("<").WriteHTML("<hr>").WriteFormatf("<span>%s%s</span>", ">", EscapeString(">"))
assert.Equal(t, "&lt;<hr><span>&gt;&gt;</span>", sb.String())
assert.NoError(t, w.Err())
}