Make it possible to configure Blackfroday per language

See #2309
This commit is contained in:
Bjørn Erik Pedersen 2016-08-07 14:03:03 +02:00
parent 596e0e98e4
commit 2079a23dd8
21 changed files with 324 additions and 189 deletions

View file

@ -59,7 +59,7 @@ type Blackfriday struct {
}
// NewBlackfriday creates a new Blackfriday filled with site config or some sane defaults.
func NewBlackfriday() *Blackfriday {
func NewBlackfriday(c ConfigProvider) *Blackfriday {
combinedParam := map[string]interface{}{
"smartypants": true,
"angledQuotes": false,
@ -72,7 +72,7 @@ func NewBlackfriday() *Blackfriday {
"sourceRelativeLinksProjectFolder": "/docs/content",
}
siteParam := viper.GetStringMap("blackfriday")
siteParam := c.GetStringMap("blackfriday")
if siteParam != nil {
siteConfig := cast.ToStringMap(siteParam)
@ -341,20 +341,25 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) {
// RenderingContext holds contextual information, like content and configuration,
// for a given content rendering.
type RenderingContext struct {
Content []byte
PageFmt string
DocumentID string
Config *Blackfriday
RenderTOC bool
FileResolver FileResolverFunc
LinkResolver LinkResolverFunc
configInit sync.Once
Content []byte
PageFmt string
DocumentID string
Config *Blackfriday
RenderTOC bool
FileResolver FileResolverFunc
LinkResolver LinkResolverFunc
ConfigProvider ConfigProvider
configInit sync.Once
}
func newViperProvidedRenderingContext() *RenderingContext {
return &RenderingContext{ConfigProvider: viper.GetViper()}
}
func (c *RenderingContext) getConfig() *Blackfriday {
c.configInit.Do(func() {
if c.Config == nil {
c.Config = NewBlackfriday()
c.Config = NewBlackfriday(c.ConfigProvider)
}
})
return c.Config