summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorNaoya Inada <naoina@kuune.org>2015-01-25 20:08:02 +0900
committerbep <bjorn.erik.pedersen@gmail.com>2015-01-26 09:55:37 +0100
commit407e80a9abbb3b22397d1ed6c62ce7cefcdd312a (patch)
tree3f05b3f3378e426043cf5e97d53d83f678143291 /hugolib
parent39b2cdece0b4be6a0d48c6b1c6a6b0c220c9bb29 (diff)
Add site-wide/per-page [blackfriday] `extensions` option
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page.go67
-rw-r--r--hugolib/page_test.go20
-rw-r--r--hugolib/shortcode.go2
-rw-r--r--hugolib/site.go4
4 files changed, 56 insertions, 37 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index eadf6eb3d..ffbe7772b 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -17,16 +17,12 @@ import (
"bytes"
"errors"
"fmt"
+ "reflect"
+
+ "github.com/mitchellh/mapstructure"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/parser"
- "reflect"
- "github.com/spf13/cast"
- "github.com/spf13/hugo/hugofs"
- "github.com/spf13/hugo/source"
- "github.com/spf13/hugo/tpl"
- jww "github.com/spf13/jwalterweatherman"
- "github.com/spf13/viper"
"html/template"
"io"
"net/url"
@@ -35,6 +31,13 @@ import (
"strings"
"sync"
"time"
+
+ "github.com/spf13/cast"
+ "github.com/spf13/hugo/hugofs"
+ "github.com/spf13/hugo/source"
+ "github.com/spf13/hugo/tpl"
+ jww "github.com/spf13/jwalterweatherman"
+ "github.com/spf13/viper"
)
type Page struct {
@@ -52,17 +55,17 @@ type Page struct {
Tmpl tpl.Template
Markup string
- extension string
- contentType string
- renderable bool
- layout string
- linkTitle string
- frontmatter []byte
- rawContent []byte
- contentShortCodes map[string]string
- plain string // TODO should be []byte
- renderingConfigFlags map[string]bool
- renderingConfigFlagsInit sync.Once
+ extension string
+ contentType string
+ renderable bool
+ layout string
+ linkTitle string
+ frontmatter []byte
+ rawContent []byte
+ contentShortCodes map[string]string
+ plain string // TODO should be []byte
+ renderingConfig *helpers.Blackfriday
+ renderingConfigInit sync.Once
PageMeta
Source
Position
@@ -182,37 +185,33 @@ func (p *Page) setSummary() {
func (p *Page) renderBytes(content []byte) []byte {
return helpers.RenderBytes(
helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
- DocumentId: p.UniqueId(), ConfigFlags: p.getRenderingConfigFlags()})
+ DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
}
func (p *Page) renderContent(content []byte) []byte {
return helpers.RenderBytesWithTOC(helpers.RenderingContext{Content: content, PageFmt: p.guessMarkupType(),
- DocumentId: p.UniqueId(), ConfigFlags: p.getRenderingConfigFlags()})
+ DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
}
-func (p *Page) getRenderingConfigFlags() map[string]bool {
-
- p.renderingConfigFlagsInit.Do(func() {
- p.renderingConfigFlags = make(map[string]bool)
+func (p *Page) getRenderingConfig() *helpers.Blackfriday {
+ p.renderingConfigInit.Do(func() {
pageParam := p.GetParam("blackfriday")
siteParam := viper.GetStringMap("blackfriday")
- p.renderingConfigFlags = cast.ToStringMapBool(siteParam)
-
if pageParam != nil {
- pageFlags := cast.ToStringMapBool(pageParam)
- for key, value := range pageFlags {
- p.renderingConfigFlags[key] = value
+ pageConfig := cast.ToStringMap(pageParam)
+ for key, value := range pageConfig {
+ siteParam[key] = value
}
}
+ p.renderingConfig = new(helpers.Blackfriday)
+ if err := mapstructure.Decode(siteParam, p.renderingConfig); err != nil {
+ jww.FATAL.Printf("Failed to get rendering config for %s:\n%s", p.BaseFileName(), err.Error())
+ }
})
- return p.renderingConfigFlags
-}
-
-func (p *Page) isRenderingFlagEnabled(flag string) bool {
- return p.getRenderingConfigFlags()[flag]
+ return p.renderingConfig
}
func newPage(filename string) *Page {
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index d4ce7a0a0..dc8ebf64b 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -213,6 +213,16 @@ the cylinder and strike me down. ## BB
"You're a great Granser," he cried delightedly, "always making believe them little marks mean something."
`
+
+ SIMPLE_PAGE_WITH_ADDITIONAL_EXTENSION = `+++
+[blackfriday]
+ extensions = ["hardLineBreak"]
++++
+first line.
+second line.
+
+fourth line.
+`
)
var PAGE_WITH_VARIOUS_FRONTMATTER_TYPES = `+++
@@ -366,6 +376,16 @@ func TestPageWithEmbeddedScriptTag(t *testing.T) {
checkPageContent(t, p, "<script type='text/javascript'>alert('the script tags are still there, right?');</script>\n")
}
+func TestPageWithAdditionalExtension(t *testing.T) {
+ p, _ := NewPage("simple.md")
+ err := p.ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_ADDITIONAL_EXTENSION))
+ p.Convert()
+ if err != nil {
+ t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
+ }
+ checkPageContent(t, p, "<p>first line.<br />\nsecond line.</p>\n\n<p>fourth line.</p>\n")
+}
+
func TestTableOfContents(t *testing.T) {
p, _ := NewPage("tocpage.md")
err := p.ReadFrom(strings.NewReader(PAGE_WITH_TOC))
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index ff3eaeb89..03cd7d4a7 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -205,7 +205,7 @@ func renderShortcode(sc shortcode, p *Page, t tpl.Template) string {
if sc.doMarkup {
newInner := helpers.RenderBytes(helpers.RenderingContext{
Content: []byte(inner), PageFmt: p.guessMarkupType(),
- DocumentId: p.UniqueId(), ConfigFlags: p.getRenderingConfigFlags()})
+ DocumentId: p.UniqueId(), Config: p.getRenderingConfig()})
// If the type is “unknown” or “markdown”, we assume the markdown
// generation has been performed. Given the input: `a line`, markdown
diff --git a/hugolib/site.go b/hugolib/site.go
index 39e900cfd..a6a18a2fe 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -187,9 +187,9 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool) (string, error
if refUrl.Fragment != "" {
link = link + "#" + refUrl.Fragment
- if refUrl.Path != "" && target != nil && !target.isRenderingFlagEnabled("plainIdAnchors") {
+ if refUrl.Path != "" && target != nil && !target.getRenderingConfig().PlainIdAnchors {
link = link + ":" + target.UniqueId()
- } else if page != nil && !page.isRenderingFlagEnabled("plainIdAnchors") {
+ } else if page != nil && !page.getRenderingConfig().PlainIdAnchors {
link = link + ":" + page.UniqueId()
}
}