fix: include last line in file previews with no trailing newline

This commit is contained in:
Solomon Victorino 2024-08-24 09:47:04 -06:00
parent 904e1239a8
commit 8f53a69c2e
6 changed files with 39 additions and 4 deletions

View file

@ -7,6 +7,7 @@ import (
"bufio"
"bytes"
"html/template"
"io"
"regexp"
"slices"
"strconv"
@ -184,10 +185,12 @@ func newFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
lineBuffer := new(bytes.Buffer)
for i := 0; i < lineCount; i++ {
buf, err := reader.ReadBytes('\n')
if err == nil || err == io.EOF {
lineBuffer.Write(buf)
}
if err != nil {
break
}
lineBuffer.Write(buf)
}
// highlight the file...