Trim trailing whitespace
If a license text had blank lines, they would result in a trailing whitespace when prefixed with the line comments. This change removes trailing whitespace from the middle lines, leaving top and bottom as is. Fixes #10
This commit is contained in:
20
tmpl.go
20
tmpl.go
@@ -15,9 +15,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
var licenseTemplate = make(map[string]*template.Template)
|
var licenseTemplate = make(map[string]*template.Template)
|
||||||
@@ -47,21 +50,16 @@ func prefix(l string, d *copyrightData, top, mid, bot string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
if top != "" {
|
if top != "" {
|
||||||
out.WriteString(top)
|
fmt.Fprintln(&out, top)
|
||||||
out.WriteRune('\n')
|
|
||||||
}
|
}
|
||||||
out.WriteString(mid)
|
s := bufio.NewScanner(&buf)
|
||||||
for _, c := range buf.Bytes() {
|
for s.Scan() {
|
||||||
out.WriteByte(c)
|
fmt.Fprintln(&out, strings.TrimRightFunc(mid+s.Text(), unicode.IsSpace))
|
||||||
if c == '\n' {
|
|
||||||
out.WriteString(mid)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if bot != "" {
|
if bot != "" {
|
||||||
out.WriteRune('\n')
|
fmt.Fprintln(&out, bot)
|
||||||
out.WriteString(bot)
|
|
||||||
}
|
}
|
||||||
out.Write([]byte{'\n', '\n'})
|
fmt.Fprintln(&out)
|
||||||
return out.Bytes(), nil
|
return out.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user