Fix defaults for Blackfriday

This commit is contained in:
Naoya Inada 2015-02-01 02:24:00 +09:00 committed by bep
parent f264076f66
commit d1364ffb68
3 changed files with 13 additions and 6 deletions

View file

@ -138,7 +138,7 @@ func InitializeConfig() {
viper.SetDefault("NewContentEditor", "")
viper.SetDefault("Paginate", 10)
viper.SetDefault("PaginatePath", "page")
viper.SetDefault("Blackfriday", new(helpers.Blackfriday))
viper.SetDefault("Blackfriday", helpers.NewBlackfriday())
if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
viper.Set("BuildDrafts", Draft)

View file

@ -44,6 +44,14 @@ type Blackfriday struct {
Extensions []string
}
func NewBlackfriday() *Blackfriday {
return &Blackfriday{
AngledQuotes: false,
Fractions: true,
PlainIdAnchors: false,
}
}
var blackfridayExtensionMap = map[string]int{
"noIntraEmphasis": blackfriday.EXTENSION_NO_INTRA_EMPHASIS,
"tables": blackfriday.EXTENSION_TABLES,
@ -120,7 +128,6 @@ func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Rendere
htmlFlags := defaultFlags
htmlFlags |= blackfriday.HTML_USE_XHTML
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS
@ -128,8 +135,8 @@ func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Rendere
htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES
}
if !ctx.getConfig().Fractions {
htmlFlags &^= blackfriday.HTML_SMARTYPANTS_FRACTIONS
if ctx.getConfig().Fractions {
htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
}
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
@ -207,7 +214,7 @@ type RenderingContext struct {
func (c *RenderingContext) getConfig() *Blackfriday {
c.configInit.Do(func() {
if c.Config == nil {
c.Config = new(Blackfriday)
c.Config = NewBlackfriday()
}
})
return c.Config

View file

@ -211,7 +211,7 @@ func (p *Page) getRenderingConfig() *helpers.Blackfriday {
combinedParam[key] = value
}
}
p.renderingConfig = new(helpers.Blackfriday)
p.renderingConfig = helpers.NewBlackfriday()
if err := mapstructure.Decode(combinedParam, p.renderingConfig); err != nil {
jww.FATAL.Printf("Failed to get rendering config for %s:\n%s", p.BaseFileName(), err.Error())
}