Raw content in Jekyll markdown
This is an issue when including golang template and angular content in markdown, both of which use {{ and }}
You need to surround the content with the {%raw%} and {%endraw%} tags
i.e. for a golang program using a text template
package main
import (
"os"
"text/template"
)
func main() {
ted := struct {
Name string
}{"ted"}
tmpl, err := template.New("test").Parse("His name is {{.Name}}\n")
if err != nil {
panic(err)
}
err = tmpl.Execute(os.Stdout, ted)
if err != nil {
panic(err)
}
}
the issue is with the “His name is {{.Name}}\n” parameter to the template’s Parse method, you can
- Surround the entire content with {%raw%} and {%endraw%} tags, less work
- Surround only the piece that causes the issue with {%raw%} and {%endraw%} tags
Surround the entire content with {%raw%} and {%endraw%} tags
{%raw%}
package main
import (
"os"
"text/template"
)
func main() {
ted := struct {
Name string
}{"ted"}
tmpl, err := template.New("test").Parse("His name is {{.Name}}\n")
if err != nil {
panic(err)
}
err = tmpl.Execute(os.Stdout, ted)
if err != nil {
panic(err)
}
}
{%endraw%}
Surround only the piece that causes the issue with {%raw%} and {%endraw%} tags
package main
import (
"os"
"text/template"
)
func main() {
ted := struct {
Name string
}{"ted"}
tmpl, err := template.New("test").Parse("His name is {%raw%}{{.Name}}{%endraw%}\n")
if err != nil {
panic(err)
}
err = tmpl.Execute(os.Stdout, ted)
if err != nil {
panic(err)
}
}