// ContentSpec provides functionality to render markdown content.
type ContentSpec struct {
- blackfriday map[string]interface{}
+ BlackFriday *BlackFriday
footnoteAnchorPrefix string
footnoteReturnLinkContents string
// SummaryLength is the length of the summary that Hugo extracts from a content.
// NewContentSpec returns a ContentSpec initialized
// with the appropriate fields from the given config.Provider.
func NewContentSpec(cfg config.Provider) (*ContentSpec, error) {
+ bf := newBlackfriday(cfg.GetStringMap("blackfriday"))
spec := &ContentSpec{
- blackfriday: cfg.GetStringMap("blackfriday"),
+ BlackFriday: bf,
footnoteAnchorPrefix: cfg.GetString("footnoteAnchorPrefix"),
footnoteReturnLinkContents: cfg.GetString("footnoteReturnLinkContents"),
summaryLength: cfg.GetInt("summaryLength"),
return spec, nil
}
-// Blackfriday holds configuration values for Blackfriday rendering.
-type Blackfriday struct {
+// BlackFriday holds configuration values for BlackFriday rendering.
+type BlackFriday struct {
Smartypants bool
SmartypantsQuotesNBSP bool
AngledQuotes bool
}
// NewBlackfriday creates a new Blackfriday filled with site config or some sane defaults.
-func (c ContentSpec) NewBlackfriday() *Blackfriday {
+func newBlackfriday(config map[string]interface{}) *BlackFriday {
defaultParam := map[string]interface{}{
"smartypants": true,
"angledQuotes": false,
siteConfig[k] = v
}
- if c.blackfriday != nil {
- for k, v := range c.blackfriday {
+ if config != nil {
+ for k, v := range config {
siteConfig[k] = v
}
}
- combinedConfig := &Blackfriday{}
+ combinedConfig := &BlackFriday{}
if err := mapstructure.Decode(siteConfig, combinedConfig); err != nil {
jww.FATAL.Printf("Failed to get site rendering config\n%s", err.Error())
}
PageFmt string
DocumentID string
DocumentName string
- Config *Blackfriday
+ Config *BlackFriday
RenderTOC bool
Cfg config.Provider
}
// Renders a codeblock using Blackfriday
func (c ContentSpec) render(input string) string {
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
render := c.getHTMLRenderer(0, ctx)
buf := &bytes.Buffer{}
// Renders a codeblock using Mmark
func (c ContentSpec) renderWithMmark(input string) string {
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
render := c.getMmarkHTMLRenderer(0, ctx)
buf := &bytes.Buffer{}
<p>END</p>
`},
} {
- blackFridayConfig := c.NewBlackfriday()
+ blackFridayConfig := c.BlackFriday
blackFridayConfig.TaskLists = this.taskListEnabled
ctx := &RenderingContext{Content: []byte(this.markdown), PageFmt: "markdown", Config: blackFridayConfig}
func TestGetHTMLRendererFlags(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
renderer := c.getHTMLRenderer(blackfriday.HTML_USE_XHTML, ctx)
flags := renderer.GetFlags()
if flags&blackfriday.HTML_USE_XHTML != blackfriday.HTML_USE_XHTML {
{blackfriday.HTML_SMARTYPANTS_LATEX_DASHES},
}
defaultFlags := blackfriday.HTML_USE_XHTML
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.Config.AngledQuotes = true
ctx.Config.Fractions = true
ctx.Config.HrefTargetBlank = true
func TestGetHTMLRendererAnchors(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.DocumentID = "testid"
ctx.Config.PlainIDAnchors = false
func TestGetMmarkHTMLRenderer(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.DocumentID = "testid"
ctx.Config.PlainIDAnchors = false
actualRenderer := c.getMmarkHTMLRenderer(0, ctx)
func TestGetMarkdownExtensionsMasksAreRemovedFromExtensions(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{"headerId"}
ctx.Config.ExtensionsMask = []string{"noIntraEmphasis"}
testFlag int
}
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{""}
ctx.Config.ExtensionsMask = []string{""}
allExtensions := []data{
func TestGetMarkdownExtensionsAddingFlagsThroughRenderingContext(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{"definitionLists"}
ctx.Config.ExtensionsMask = []string{""}
func TestGetMarkdownRenderer(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.Content = []byte("testContent")
actualRenderedMarkdown := c.markdownRender(ctx)
expectedRenderedMarkdown := []byte("<p>testContent</p>\n")
func TestGetMarkdownRendererWithTOC(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{RenderTOC: true, Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{RenderTOC: true, Cfg: c.cfg, Config: c.BlackFriday}
ctx.Content = []byte("testContent")
actualRenderedMarkdown := c.markdownRender(ctx)
expectedRenderedMarkdown := []byte("<nav>\n</nav>\n\n<p>testContent</p>\n")
testFlag int
}
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.Config.Extensions = []string{"tables"}
ctx.Config.ExtensionsMask = []string{""}
allExtensions := []data{
func TestMmarkRender(t *testing.T) {
c := newTestContentSpec()
- ctx := &RenderingContext{Cfg: c.cfg, Config: c.NewBlackfriday()}
+ ctx := &RenderingContext{Cfg: c.cfg, Config: c.BlackFriday}
ctx.Content = []byte("testContent")
actualRenderedMarkdown := c.mmarkRender(ctx)
expectedRenderedMarkdown := []byte("<p>testContent</p>\n")
v.SetDefault("paginate", 10)
v.SetDefault("paginatePath", "page")
v.SetDefault("summaryLength", 70)
- v.SetDefault("blackfriday", c.NewBlackfriday())
+ v.SetDefault("blackfriday", c.BlackFriday)
v.SetDefault("rSSUri", "index.xml")
v.SetDefault("rssLimit", -1)
v.SetDefault("sectionPagesMenu", "")
plainWords []string
// rendering configuration
- renderingConfig *helpers.Blackfriday
+ renderingConfig *helpers.BlackFriday
// menus
pageMenus PageMenus
Config: p.getRenderingConfig()})
}
-func (p *Page) getRenderingConfig() *helpers.Blackfriday {
+func (p *Page) getRenderingConfig() *helpers.BlackFriday {
p.renderingConfigInit.Do(func() {
- p.renderingConfig = p.s.ContentSpec.NewBlackfriday()
-
- if p.Language() == nil {
- panic(fmt.Sprintf("nil language for %s with source lang %s", p.BaseFileName(), p.lang))
- }
-
bfParam := p.GetParam("blackfriday")
if bfParam == nil {
+ p.renderingConfig = p.s.ContentSpec.BlackFriday
return
}
+ // Create a copy so we can modify it.
+ bf := *p.s.ContentSpec.BlackFriday
+ p.renderingConfig = &bf
+
+ if p.Language() == nil {
+ panic(fmt.Sprintf("nil language for %s with source lang %s", p.BaseFileName(), p.lang))
+ }
pageParam := cast.ToStringMap(bfParam)
if err := mapstructure.Decode(pageParam, &p.renderingConfig); err != nil {
Cfg: ns.deps.Cfg,
Content: []byte(ss),
PageFmt: "markdown",
- Config: ns.deps.ContentSpec.NewBlackfriday(),
+ Config: ns.deps.ContentSpec.BlackFriday,
},
)