diff --git a/hugolib/helpers.go b/hugolib/helpers.go index 08fafd37f..f9283f4b8 100644 --- a/hugolib/helpers.go +++ b/hugolib/helpers.go @@ -15,6 +15,7 @@ package hugolib import ( "bytes" + "html/template" "errors" "fmt" "github.com/kr/pretty" @@ -164,11 +165,11 @@ func Urlize(url string) string { return Sanitize(strings.ToLower(strings.Replace(strings.TrimSpace(url), " ", "-", -1))) } -func AbsUrl(url string, base string) HTML { +func AbsUrl(url string, base string) template.HTML { if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") { - return HTML(url) + return template.HTML(url) } - return HTML(MakePermalink(base, url)) + return template.HTML(MakePermalink(base, url)) } func Gt(a interface{}, b interface{}) bool { diff --git a/hugolib/node.go b/hugolib/node.go index a8e90b7d8..404944d9d 100644 --- a/hugolib/node.go +++ b/hugolib/node.go @@ -15,10 +15,11 @@ package hugolib import ( "time" + "html/template" ) type Node struct { - RSSlink HTML + RSSlink template.HTML Site SiteInfo layout string Data map[string]interface{} @@ -31,7 +32,7 @@ type Node struct { type UrlPath struct { Url string - Permalink HTML + Permalink template.HTML Slug string Section string Path string diff --git a/hugolib/page.go b/hugolib/page.go index 5b2b29704..a8629250b 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -22,6 +22,7 @@ import ( "github.com/BurntSushi/toml" "github.com/theplant/blackfriday" "io" + "html/template" "io/ioutil" "launchpad.net/goyaml" "os" @@ -37,8 +38,8 @@ var _ = filepath.Base("") type Page struct { Status string Images []string - Content HTML - Summary HTML + Content template.HTML + Summary template.HTML RawMarkdown string // TODO should be []byte Params map[string]interface{} RenderedContent *bytes.Buffer @@ -184,7 +185,7 @@ func splitPageContent(data []byte, start string, end string) ([]string, []string return datum, lines } -func (p *Page) Permalink() HTML { +func (p *Page) Permalink() template.HTML { baseUrl := string(p.Site.BaseUrl) section := strings.TrimSpace(p.Section) pSlug := strings.TrimSpace(p.Slug) @@ -208,7 +209,7 @@ func (p *Page) Permalink() HTML { path = section + "/" + file } } - return HTML(MakePermalink(baseUrl, path)) + return template.HTML(MakePermalink(baseUrl, path)) } func (page *Page) handleTomlMetaData(datum []byte) (interface{}, error) { @@ -426,14 +427,14 @@ func chompWhitespace(data *bufio.Reader) (r rune, err error) { } } -func (p *Page) Render(layout ...string) HTML { +func (p *Page) Render(layout ...string) template.HTML { curLayout := "" if len(layout) > 0 { curLayout = layout[0] } - return HTML(string(p.ExecuteTemplate(curLayout).Bytes())) + return template.HTML(string(p.ExecuteTemplate(curLayout).Bytes())) } func (p *Page) ExecuteTemplate(layout string) *bytes.Buffer { @@ -480,12 +481,12 @@ func (page *Page) convertMarkdown(lines io.Reader) { b := new(bytes.Buffer) b.ReadFrom(lines) content := b.Bytes() - page.Content = HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content)))) + page.Content = template.HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content)))) summary, plain := getSummaryString(content) if plain { - page.Summary = HTML(string(summary)) + page.Summary = template.HTML(string(summary)) } else { - page.Summary = HTML(string(blackfriday.MarkdownCommon(summary))) + page.Summary = template.HTML(string(blackfriday.MarkdownCommon(summary))) } } @@ -493,11 +494,11 @@ func (page *Page) convertRestructuredText(lines io.Reader) { b := new(bytes.Buffer) b.ReadFrom(lines) content := b.Bytes() - page.Content = HTML(getRstContent(content)) + page.Content = template.HTML(getRstContent(content)) summary, plain := getSummaryString(content) if plain { - page.Summary = HTML(string(summary)) + page.Summary = template.HTML(string(summary)) } else { - page.Summary = HTML(getRstContent(summary)) + page.Summary = template.HTML(getRstContent(summary)) } } diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 99f7c3a1a..f321a1655 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -4,6 +4,7 @@ import ( "path/filepath" "strings" "testing" + "html/template" ) var EMPTY_PAGE = "" @@ -141,13 +142,13 @@ func checkPageTitle(t *testing.T, page *Page, title string) { } func checkPageContent(t *testing.T, page *Page, content string) { - if page.Content != HTML(content) { + if page.Content != template.HTML(content) { t.Fatalf("Page content is: %s. Expected %s", page.Content, content) } } func checkPageSummary(t *testing.T, page *Page, summary string) { - if page.Summary != HTML(summary) { + if page.Summary != template.HTML(summary) { t.Fatalf("Page summary is: `%s`. Expected `%s`", page.Summary, summary) } } diff --git a/hugolib/site.go b/hugolib/site.go index 2c6c610bf..0c2209cb9 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -15,6 +15,7 @@ package hugolib import ( "bitbucket.org/pkg/inflect" + "html/template" "bytes" "fmt" "github.com/spf13/hugo/target" @@ -41,7 +42,7 @@ type Site struct { } type SiteInfo struct { - BaseUrl URL + BaseUrl template.URL Indexes OrderedIndexList Recent *Pages LastChange time.Time @@ -169,7 +170,7 @@ func (s *Site) initialize() { filepath.Walk(s.absContentDir(), walker) s.Info = SiteInfo{ - BaseUrl: URL(s.Config.BaseUrl), + BaseUrl: template.URL(s.Config.BaseUrl), Title: s.Config.Title, Recent: &s.Pages, Config: &s.Config, @@ -206,7 +207,7 @@ func (s *Site) checkDirectories() { func (s *Site) ProcessShortcodes() { for _, page := range s.Pages { - page.Content = HTML(ShortcodesHandle(string(page.Content), page, s.Tmpl)) + page.Content = template.HTML(ShortcodesHandle(string(page.Content), page, s.Tmpl)) } } @@ -220,7 +221,7 @@ func (s *Site) AbsUrlify() { content = strings.Replace(content, " href='/", " href='"+baseWithSlash, -1) content = strings.Replace(content, " href=\"/", " href=\""+baseWithSlash, -1) content = strings.Replace(content, baseWithoutTrailingSlash+"//", baseWithSlash, -1) - page.Content = HTML(content) + page.Content = template.HTML(content) } } @@ -525,7 +526,7 @@ func (s *Site) RenderLists() error { } else { n.Url = Urlize(section + "/" + "index.xml") } - n.Permalink = HTML(string(n.Site.BaseUrl) + n.Url) + n.Permalink = template.HTML(string(n.Site.BaseUrl) + n.Url) y := s.NewXMLBuffer() s.Tmpl.ExecuteTemplate(y, "rss.xml", n) err = s.WritePublic(section+"/index.xml", y.Bytes()) @@ -591,8 +592,8 @@ func (s *Site) Stats() { } } -func permalink(s *Site, plink string) HTML { - return HTML(MakePermalink(string(s.Info.BaseUrl), plink)) +func permalink(s *Site, plink string) template.HTML { + return template.HTML(MakePermalink(string(s.Info.BaseUrl), plink)) } func (s *Site) NewNode() *Node { diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 08906e794..25171d256 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" "testing" + "html/template" ) var TEMPLATE_TITLE = "{{ .Title }}" @@ -104,7 +105,7 @@ func TestRenderThing(t *testing.T) { }{ {PAGE_SIMPLE_TITLE, TEMPLATE_TITLE, "simple template"}, {PAGE_SIMPLE_TITLE, TEMPLATE_FUNC, "simple-template"}, - {PAGE_WITH_MD, TEMPLATE_CONTENT, "

heading 1

\n

text

\n

heading 2

\n

more text

\n"}, + {PAGE_WITH_MD, TEMPLATE_CONTENT, "

heading 1

\n\n

text

\n\n

heading 2

\n\n

more text

\n"}, } s := new(Site) @@ -121,6 +122,7 @@ func TestRenderThing(t *testing.T) { t.Fatalf("Unable to add template") } + p.Content = template.HTML(p.Content) html, err2 := s.RenderThing(p, templateName) if err2 != nil { t.Errorf("Unable to render html: %s", err) diff --git a/hugolib/template.go b/hugolib/template.go index f275c0cb9..8dd382379 100644 --- a/hugolib/template.go +++ b/hugolib/template.go @@ -14,7 +14,6 @@ import ( // It should not be used for HTML from a third-party, or HTML with // unclosed tags or comments. The outputs of a sound HTML sanitizer // and a template escaped by this package are fine for use with HTML. -type HTML template.HTML type Template interface { ExecuteTemplate(wr io.Writer, name string, data interface{}) error @@ -25,8 +24,6 @@ type Template interface { AddTemplate(name, tpl string) error } -type URL template.URL - type templateErr struct { name string err error