diff --git a/helpers/content.go b/helpers/content.go index 709dc8a97..204a56104 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -241,16 +241,15 @@ func getMarkdownExtensions(ctx *RenderingContext) int { } func markdownRender(ctx *RenderingContext) []byte { + if ctx.RenderTOC { + return blackfriday.Markdown(ctx.Content, + getHTMLRenderer(blackfriday.HTML_TOC, ctx), + getMarkdownExtensions(ctx)) + } return blackfriday.Markdown(ctx.Content, getHTMLRenderer(0, ctx), getMarkdownExtensions(ctx)) } -func markdownRenderWithTOC(ctx *RenderingContext) []byte { - return blackfriday.Markdown(ctx.Content, - getHTMLRenderer(blackfriday.HTML_TOC, ctx), - getMarkdownExtensions(ctx)) -} - // getMmarkHTMLRenderer creates a new mmark HTML Renderer with the given configuration. func getMmarkHTMLRenderer(defaultFlags int, ctx *RenderingContext) mmark.Renderer { renderParameters := mmark.HtmlRendererParameters{ @@ -345,6 +344,7 @@ type RenderingContext struct { PageFmt string DocumentID string Config *Blackfriday + RenderTOC bool FileResolver FileResolverFunc LinkResolver LinkResolverFunc configInit sync.Once @@ -359,22 +359,6 @@ func (c *RenderingContext) getConfig() *Blackfriday { return c.Config } -// RenderBytesWithTOC renders a []byte with table of contents included. -func RenderBytesWithTOC(ctx *RenderingContext) []byte { - switch ctx.PageFmt { - default: - return markdownRenderWithTOC(ctx) - case "markdown": - return markdownRenderWithTOC(ctx) - case "asciidoc": - return []byte(getAsciidocContent(ctx.Content)) - case "mmark": - return mmarkRender(ctx) - case "rst": - return []byte(getRstContent(ctx.Content)) - } -} - // RenderBytes renders a []byte. func RenderBytes(ctx *RenderingContext) []byte { switch ctx.PageFmt { diff --git a/helpers/content_test.go b/helpers/content_test.go index a89b4992e..8aa645f6b 100644 --- a/helpers/content_test.go +++ b/helpers/content_test.go @@ -289,10 +289,10 @@ func TestGetMarkdownRenderer(t *testing.T) { } func TestGetMarkdownRendererWithTOC(t *testing.T) { - ctx := &RenderingContext{} + ctx := &RenderingContext{RenderTOC: true} ctx.Content = []byte("testContent") ctx.Config = ctx.getConfig() - actualRenderedMarkdown := markdownRenderWithTOC(ctx) + actualRenderedMarkdown := markdownRender(ctx) expectedRenderedMarkdown := []byte("\n\n

testContent

\n") if !bytes.Equal(actualRenderedMarkdown, expectedRenderedMarkdown) { t.Errorf("Actual rendered Markdown (%s) did not match expected markdown (%s)", actualRenderedMarkdown, expectedRenderedMarkdown) diff --git a/hugolib/page.go b/hugolib/page.go index 9616bfbbd..f64cdf95f 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -280,7 +280,7 @@ func (p *Page) renderContent(content []byte) []byte { return p.Node.Site.SourceRelativeLinkFile(ref, p) } } - return helpers.RenderBytesWithTOC(&helpers.RenderingContext{Content: content, PageFmt: p.determineMarkupType(), + return helpers.RenderBytes(&helpers.RenderingContext{Content: content, RenderTOC: true, PageFmt: p.determineMarkupType(), DocumentID: p.UniqueID(), Config: p.getRenderingConfig(), LinkResolver: fn, FileResolver: fileFn}) }