Skip to content

Commit 4969aec

Browse files
author
coldstar
committed
clear go template generated black lines
1 parent 14ab7a6 commit 4969aec

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

context.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package baa
22

33
import (
4+
"bufio"
45
"bytes"
56
"encoding/xml"
67
"errors"
@@ -532,7 +533,24 @@ func (c *Context) Fetch(tpl string) ([]byte, error) {
532533
if err := c.baa.Render().Render(buf, tpl, c.Gets()); err != nil {
533534
return nil, err
534535
}
535-
return buf.Bytes(), nil
536+
537+
// clear go template generated black lines
538+
nbuf := new(bytes.Buffer)
539+
r := bufio.NewReader(buf)
540+
for {
541+
line, _, err := r.ReadLine()
542+
if err != nil {
543+
break
544+
}
545+
clearLine := strings.TrimSpace(string(line))
546+
if len(clearLine) == 0 {
547+
continue
548+
}
549+
nbuf.Write(line)
550+
nbuf.WriteRune('\n')
551+
}
552+
553+
return nbuf.Bytes(), nil
536554
}
537555

538556
// Redirect redirects the request using http.Redirect with status code.

0 commit comments

Comments
 (0)