I found that workaround as well but the issue is that whenever I have content spanning multiple lines that are surrounded in the short-codes, it is very ugly.
I’m pretty confident that the shortcode parser/handler does not add anything, so I would expect the same as you in the above. But whitespace in Go templates is little bit of a mystery.
So, if you could try the same construct (if possible) in a regular template and see how that works …
package main
import (
"os"
"text/template"
"fmt"
)
type Data struct {
Content string
}
func main() {
validData := Data{"highlight: true"}
brokenData := Data{"\nhighlight: true"}
tmpl, err := template.New("test").Parse("{{- .Content -}}")
if err != nil { panic(err) }
fmt.Printf("Doesn't contain a new line\n")
err = tmpl.Execute(os.Stdout, validData)
if err != nil { panic(err) }
fmt.Printf("\nContains a new line but should be removed\n")
err = tmpl.Execute(os.Stdout, brokenData)
if err != nil { panic(err) }
}
If you run the above example, the second data entry (brokenData) contains a new line but Go doesn’t seem to be stripping like it is supposed to. So is the issue with Go itself or is my test wrong?