github.com/linchen2chris/hugo@v0.0.0-20230307053224-cec209389705/markup/goldmark/links/integration_test.go (about) 1 package images_test 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/gohugoio/hugo/hugolib" 8 ) 9 10 func TestDisableWrapStandAloneImageWithinParagraph(t *testing.T) { 11 t.Parallel() 12 13 filesTemplate := ` 14 -- config.toml -- 15 [markup.goldmark.renderer] 16 unsafe = false 17 [markup.goldmark.parser] 18 wrapStandAloneImageWithinParagraph = CONFIG_VALUE 19 [markup.goldmark.parser.attribute] 20 block = true 21 title = true 22 -- content/p1.md -- 23 --- 24 title: "p1" 25 --- 26 27 This is an inline image: . Some more text. 28 29  30 {.b} 31 32 33 -- layouts/_default/single.html -- 34 {{ .Content }} 35 ` 36 37 t.Run("With Hook, no wrap", func(t *testing.T) { 38 files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false") 39 files = files + `-- layouts/_default/_markup/render-image.html -- 40 {{ if .IsBlock }} 41 <figure class="{{ .Attributes.class }}"> 42 <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}|{{ .Ordinal }}" /> 43 </figure> 44 {{ else }} 45 <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}|{{ .Ordinal }}" /> 46 {{ end }} 47 ` 48 b := hugolib.NewIntegrationTestBuilder( 49 hugolib.IntegrationTestConfig{ 50 T: t, 51 TxtarString: files, 52 NeedsOsFS: false, 53 }, 54 ).Build() 55 56 b.AssertFileContent("public/p1/index.html", 57 "This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image|0\" />\n. Some more text.</p>", 58 "<figure class=\"b\">\n\t<img src=\"/block.jpg\" alt=\"Block Image|1\" />", 59 ) 60 }) 61 62 t.Run("With Hook, wrap", func(t *testing.T) { 63 files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true") 64 files = files + `-- layouts/_default/_markup/render-image.html -- 65 {{ if .IsBlock }} 66 <figure class="{{ .Attributes.class }}"> 67 <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" /> 68 </figure> 69 {{ else }} 70 <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" /> 71 {{ end }} 72 ` 73 b := hugolib.NewIntegrationTestBuilder( 74 hugolib.IntegrationTestConfig{ 75 T: t, 76 TxtarString: files, 77 NeedsOsFS: false, 78 }, 79 ).Build() 80 81 b.AssertFileContent("public/p1/index.html", 82 "This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image\" />\n. Some more text.</p>", 83 "<p class=\"b\">\n\t<img src=\"/block.jpg\" alt=\"Block Image\" />\n</p>", 84 ) 85 }) 86 87 t.Run("No Hook, no wrap", func(t *testing.T) { 88 files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false") 89 b := hugolib.NewIntegrationTestBuilder( 90 hugolib.IntegrationTestConfig{ 91 T: t, 92 TxtarString: files, 93 NeedsOsFS: false, 94 }, 95 ).Build() 96 97 b.AssertFileContent("public/p1/index.html", "<p>This is an inline image: <img src=\"/inline.jpg\" alt=\"Inline Image\">. Some more text.</p>\n<img src=\"/block.jpg\" alt=\"Block Image\" class=\"b\">") 98 }) 99 100 t.Run("No Hook, wrap", func(t *testing.T) { 101 files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true") 102 b := hugolib.NewIntegrationTestBuilder( 103 hugolib.IntegrationTestConfig{ 104 T: t, 105 TxtarString: files, 106 NeedsOsFS: false, 107 }, 108 ).Build() 109 110 b.AssertFileContent("public/p1/index.html", "<p class=\"b\"><img src=\"/block.jpg\" alt=\"Block Image\"></p>") 111 }) 112 113 }