}
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{
PageFmt string
DocumentID string
Config *Blackfriday
+ RenderTOC bool
FileResolver FileResolverFunc
LinkResolver LinkResolverFunc
configInit sync.Once
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 {
}
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)
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})
}