fix: include last line in file previews with no trailing newline
This commit is contained in:
parent
904e1239a8
commit
8f53a69c2e
6 changed files with 39 additions and 4 deletions
|
@ -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...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue