Consolidate the Render funcs

This commit is contained in:
Bjørn Erik Pedersen 2016-07-10 11:36:25 +02:00
parent 4a48b5f326
commit 1d7f4413f5
3 changed files with 9 additions and 25 deletions

View file

@ -241,14 +241,13 @@ func getMarkdownExtensions(ctx *RenderingContext) int {
}
func markdownRender(ctx *RenderingContext) []byte {
return blackfriday.Markdown(ctx.Content, getHTMLRenderer(0, ctx),
getMarkdownExtensions(ctx))
}
func markdownRenderWithTOC(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))
}
// getMmarkHTMLRenderer creates a new mmark HTML Renderer with the given configuration.
@ -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 {

View file

@ -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)

View file

@ -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})
}