package images_test import ( "strings" "testing" "github.com/gohugoio/hugo/hugolib" ) func TestDisableWrapStandAloneImageWithinParagraph(t *testing.T) { t.Parallel() filesTemplate := ` -- config.toml -- [markup.goldmark.renderer] unsafe = false [markup.goldmark.parser] wrapStandAloneImageWithinParagraph = CONFIG_VALUE [markup.goldmark.parser.attribute] block = true title = true -- content/p1.md -- --- title: "p1" --- This is an inline image: ![Inline Image](/inline.jpg). Some more text. ![Block Image](/block.jpg) {.b} -- layouts/_default/single.html -- {{ .Content }} ` t.Run("With Hook, no wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false") files = files + `-- layouts/_default/_markup/render-image.html -- {{ if .IsBlock }}
{{ .Text }}
{{ else }} {{ .Text }} {{ end }} ` b := hugolib.NewIntegrationTestBuilder( hugolib.IntegrationTestConfig{ T: t, TxtarString: files, NeedsOsFS: false, }, ).Build() b.AssertFileContent("public/p1/index.html", "This is an inline image: \n\t\"Inline\n. Some more text.

", "
\n\t\"Block", ) }) t.Run("With Hook, wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true") files = files + `-- layouts/_default/_markup/render-image.html -- {{ if .IsBlock }}
{{ .Text }}
{{ else }} {{ .Text }} {{ end }} ` b := hugolib.NewIntegrationTestBuilder( hugolib.IntegrationTestConfig{ T: t, TxtarString: files, NeedsOsFS: false, }, ).Build() b.AssertFileContent("public/p1/index.html", "This is an inline image: \n\t\"Inline\n. Some more text.

", "

\n\t\"Block\n

", ) }) t.Run("No Hook, no wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false") b := hugolib.NewIntegrationTestBuilder( hugolib.IntegrationTestConfig{ T: t, TxtarString: files, NeedsOsFS: false, }, ).Build() b.AssertFileContent("public/p1/index.html", "

This is an inline image: \"Inline. Some more text.

\n\"Block") }) t.Run("No Hook, wrap", func(t *testing.T) { files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true") b := hugolib.NewIntegrationTestBuilder( hugolib.IntegrationTestConfig{ T: t, TxtarString: files, NeedsOsFS: false, }, ).Build() b.AssertFileContent("public/p1/index.html", "

\"Block

") }) }