I'm using a Go template to output html, and inserting some values through a pipeline. The thing is one of the values a raw html that I don't want to be escaped. But when the template is executed, it is escaped.
This is the code
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"html/template"
"encoding/xml"
)
type RSS struct {
XMLName xml.Name `xml:"rss"`
Items Items `xml:"channel"`
}
type Items struct {
XMLName xml.Name `xml:"channel"`
ItemList []Item `xml:"item"`
}
type Item struct {
Title string `xml:"title"`
Link string `xml:"link"`
Description string `xml:"description"`
}
func main() {
res, err := http.Get("http://news.google.com/news?hl=en&gl=us&q=samsung&um=1&ie=UTF-8&output=rss")
if err != nil {
log.Fatal(err)
}
asText, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
var i RSS
err = xml.Unmarshal([]byte(asText), &i)
if err != nil {
log.Fatal(err)
}
res.Body.Close()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
handler(w, r, i)
})
http.ListenAndServe(":8080", nil)
}
func handler(w http.ResponseWriter, r *http.Request, i RSS) {
t, _ := template.ParseFiles("index.html")
t.Execute(w, i.Items)
}
this is the html:
<html>
<head>
</head>
<body>
{{range .ItemList}}
<div class="news-item">
<p>
<a href="{{.Link}}">{{.Title}}</a>
</p>
<p>{{.Description}}</p>
</div>
{{end}}
</body>
</html>
and the output looks like this:
<div class="news-item">
<p>
<a href="http://news.google.com/news/url?sa=t&fd=R&usg=AFQjCNFd-5CF7Rwy7sjNZ2-fSOLkO6ri5g&url=http://www.pehub.com/186539/what-apple-might-learn-samsung/">What Apple Might Learn from Samsung - Private Equity Hub (press release)</a>
</p>
<p><table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;"><tr><td width="80" align="center" valign="top"><font style="font-size:85%;font-family:arial,sans-serif"></font></td><td valign="top" class="j"><font style="font-size:85%;font-family:arial,sans-serif"><br /><div style="padding-top:0.8em;"><img alt="" height="1" width="1" /></div><div class="lh"><a href="http://news.google.com/news/url?sa=t&amp;fd=R&amp;usg=AFQjCNFd-5CF7Rwy7sjNZ2-fSOLkO6ri5g&amp;url=http://www.pehub.com/186539/what-apple-might-learn-samsung/"><b>What Apple Might Learn from <b>Samsung</b></b></a><br /><font size="-1"><b><font color="#6f6f6f">Private Equity Hub (press release)</font></b></font><br /><font size="-1"><b>Samsung</b> suddenly seems a lot like a boxer whose every punch at the world champion, Apple, is bringing it closer to a legitimate shot at the title. <b>Samsung&#39;s</b> handsets are hot. Late last year, <b>Samsung&#39;s</b> Galaxy S III became the best-selling smartphone in <b>...</b></font><br /><font size="-1" class="p"></font><br /><font class="p" size="-1"><a class="p" href="http://news.google.com/news/more?ncl=d2dovyDH3OFX_MM&amp;ned=us"><nobr><b></b></nobr></a></font></div></font></td></tr></table></p>
</div>
the description is escaped html, and i want it regular html