diff options
author | Bjørn Erik Pedersen <[email protected]> | 2016-07-10 11:36:25 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2016-07-10 11:36:25 +0200 |
commit | 1d7f4413f55073b9ea9a9fc9dd4f1792915fe8e1 (patch) | |
tree | 70f84d613ccaf385024bad7dc022d2b3ae11a534 /helpers | |
parent | 4a48b5f32641c15e1f79aaf7aeef25216cdc0254 (diff) | |
download | hugo-1d7f4413f55073b9ea9a9fc9dd4f1792915fe8e1.tar.gz hugo-1d7f4413f55073b9ea9a9fc9dd4f1792915fe8e1.zip |
Consolidate the Render funcs
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/content.go | 28 | ||||
-rw-r--r-- | helpers/content_test.go | 4 |
2 files changed, 8 insertions, 24 deletions
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("<nav>\n</nav>\n\n<p>testContent</p>\n") if !bytes.Equal(actualRenderedMarkdown, expectedRenderedMarkdown) { t.Errorf("Actual rendered Markdown (%s) did not match expected markdown (%s)", actualRenderedMarkdown, expectedRenderedMarkdown) |