ref: f432b187a0ec52629ad1b9d993a5c3203e3699d5
parent: a45de56db1992d469dc9b4714bd839d6c3e9b092
author: spf13 <[email protected]>
date: Fri Dec 6 18:32:00 EST 2013
render shortcodes prior to converting to html
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -36,6 +36,7 @@
type Page struct {
Status string
Images []string
+ RawContent []byte
Content template.HTML
Summary template.HTML
Truncated bool
@@ -520,17 +521,23 @@
if err = page.update(meta); err != nil {
return err
}
+
}
+ page.Content = template.HTML(p.Content())
+ return nil
+}
+
+func (page *Page) Convert() error {
switch page.guessMarkupType() {
case "md", "markdown", "mdown":
- page.convertMarkdown(bytes.NewReader(p.Content()))
+ page.convertMarkdown(bytes.NewReader([]byte(page.Content)))
case "rst":
- page.convertRestructuredText(bytes.NewReader(p.Content()))
+ page.convertRestructuredText(bytes.NewReader([]byte(page.Content)))
case "html":
fallthrough
default:
- page.Content = template.HTML(p.Content())
+ page.Content = template.HTML(page.Content)
}
return nil
}
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -227,6 +227,8 @@
func TestCreateNewPage(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE), "simple.md")
+ p.Convert()
+
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
@@ -240,6 +242,7 @@
func TestPageWithDelimiter(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER), "simple.md")
+ p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
@@ -253,6 +256,7 @@
func TestPageWithShortCodeInSummary(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SHORTCODE_IN_SUMMARY), "simple.md")
+ p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
@@ -265,6 +269,7 @@
func TestPageWithMoreTag(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE), "simple.md")
+ p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
@@ -277,6 +282,7 @@
func TestPageWithDate(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_RFC3339_DATE), "simple")
+ p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
@@ -289,6 +295,7 @@
func TestWordCount(t *testing.T) {
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_LONG_CONTENT), "simple.md")
+ p.Convert()
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -170,8 +170,6 @@
return
}
s.timerStep("render and write aliases")
- s.ProcessShortcodes()
- s.timerStep("render shortcodes")
if err = s.RenderIndexes(); err != nil {
return
}
@@ -289,6 +287,16 @@
page.Tmpl = s.Tmpl
page.Section = file.Section
page.Dir = file.Dir
+
+ // Handling short codes prior to Conversion to HTML
+ page.Content = template.HTML(ShortcodesHandle(string(page.Content), page, s.Tmpl))
+ page.Summary = template.HTML(ShortcodesHandle(string(page.Summary), page, s.Tmpl))
+
+ err = page.Convert()
+ if err != nil {
+ return err
+ }
+
if s.Config.BuildDrafts || !page.Draft {
s.Pages = append(s.Pages, page)
}
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -23,8 +23,8 @@
TEMPLATE_CONTENT = "{{ .Content }}"
TEMPLATE_DATE = "{{ .Date }}"
INVALID_TEMPLATE_FORMAT_DATE = "{{ .Date.Format time.RFC3339 }}"
- TEMPLATE_WITH_URL_REL = "<a href=\"foobar.jpg\">Going</a>"
- TEMPLATE_WITH_URL_ABS = "<a href=\"/foobar.jpg\">Going</a>"
+ TEMPLATE_WITH_URL_REL = "<a href=\"foobar.jpg\">Going</a>"
+ TEMPLATE_WITH_URL_ABS = "<a href=\"/foobar.jpg\">Going</a>"
PAGE_URL_SPECIFIED = `---
title: simple template
url: "mycategory/my-whatever-content/"
@@ -50,6 +50,7 @@
func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
p, _ := ReadFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
+ p.Convert()
s := new(Site)
s.prepTemplates()
err := s.renderThing(p, "foobar", nil)
@@ -106,6 +107,7 @@
for i, test := range tests {
p, err := ReadFrom(strings.NewReader(test.content), "content/a/file.md")
+ p.Convert()
if err != nil {
t.Fatalf("Error parsing buffer: %s", err)
}
@@ -234,6 +236,7 @@
Config: Config{Verbose: true, BaseUrl: "http://auth/bub"},
Source: &source.InMemorySource{sources},
}
+
s.initializeSiteInfo()
s.prepTemplates()