Skip to content

Commit

Permalink
Don't output trailing newlines for blank lines
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed May 23, 2024
1 parent cd05d8c commit 85b53eb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/toml-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,14 @@ func indentWith(s, with string) string {

func indent(s string, n int) string {
sp := strings.Repeat(" ", n)
return sp + strings.ReplaceAll(strings.TrimRight(s, "\n"), "\n", "\n"+sp)
lines := strings.Split(strings.TrimRight(s, "\n"), "\n")
for i := range lines {
lines[i] = strings.TrimRight(lines[i], " \t")
if lines[i] != "" {
lines[i] = sp + lines[i]
}
}
return strings.Join(lines, "\n")
}

func doCat(fsys fs.FS, tomlVersion string, size int, run, skip []string) {
Expand Down

0 comments on commit 85b53eb

Please sign in to comment.