mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-16 20:53:59 +02:00
Reuse the BlackFriday instance when possible
This is in heavy use in rendering, so this makes a difference: ```bash benchmark old ns/op new ns/op delta BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 124551144 107743429 -13.49% benchmark old allocs new allocs delta BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 528684 435118 -17.70% benchmark old bytes new bytes delta BenchmarkSiteBuilding/TOML,num_langs=1,num_pages=500,tags_per_page=5,shortcodes,render-4 53306848 45147832 -15.31% ```
This commit is contained in:
@@ -159,7 +159,7 @@ func TestTruncateWordsByRune(t *testing.T) {
|
||||
|
||||
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 {
|
||||
@@ -186,7 +186,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
|
||||
{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
|
||||
@@ -209,7 +209,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
|
||||
|
||||
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
|
||||
|
||||
@@ -233,7 +233,7 @@ func TestGetHTMLRendererAnchors(t *testing.T) {
|
||||
|
||||
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)
|
||||
@@ -257,7 +257,7 @@ func TestGetMmarkHTMLRenderer(t *testing.T) {
|
||||
|
||||
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"}
|
||||
|
||||
@@ -272,7 +272,7 @@ func TestGetMarkdownExtensionsByDefaultAllExtensionsAreEnabled(t *testing.T) {
|
||||
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{
|
||||
@@ -304,7 +304,7 @@ func TestGetMarkdownExtensionsByDefaultAllExtensionsAreEnabled(t *testing.T) {
|
||||
|
||||
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{""}
|
||||
|
||||
@@ -316,7 +316,7 @@ func TestGetMarkdownExtensionsAddingFlagsThroughRenderingContext(t *testing.T) {
|
||||
|
||||
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")
|
||||
@@ -327,7 +327,7 @@ func TestGetMarkdownRenderer(t *testing.T) {
|
||||
|
||||
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")
|
||||
@@ -342,7 +342,7 @@ func TestGetMmarkExtensions(t *testing.T) {
|
||||
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{
|
||||
@@ -371,7 +371,7 @@ func TestGetMmarkExtensions(t *testing.T) {
|
||||
|
||||
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")
|
||||
|
Reference in New Issue
Block a user