Debian Codegraph @

markup/goldmark/images/images_integration_test.go

raw
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 -- hugo.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: ![Inline Image](/inline.jpg). Some more text.
28
29 ![Block Image](/block.jpg)
30 {.b}
31
32
33 -- layouts/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/_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.Test(t, files)
49
50 b.AssertFileContent("public/p1/index.html",
51 "This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image|0\" />\n. Some more text.</p>",
52 "<figure class=\"b\">\n\t<img src=\"/block.jpg\" alt=\"Block Image|1\" />",
53 )
54 })
55
56 t.Run("With Hook, wrap", func(t *testing.T) {
57 files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true")
58 files = files + `-- layouts/_markup/render-image.html --
59 {{ if .IsBlock }}
60 <figure class="{{ .Attributes.class }}">
61 <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
62 </figure>
63 {{ else }}
64 <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
65 {{ end }}
66 `
67 b := hugolib.Test(t, files)
68
69 b.AssertFileContent("public/p1/index.html",
70 "This is an inline image: \n\t<img src=\"/inline.jpg\" alt=\"Inline Image\" />\n. Some more text.</p>",
71 "<p class=\"b\">\n\t<img src=\"/block.jpg\" alt=\"Block Image\" />\n</p>",
72 )
73 })
74
75 t.Run("No Hook, no wrap", func(t *testing.T) {
76 files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false")
77 b := hugolib.Test(t, files)
78
79 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\">")
80 })
81
82 t.Run("No Hook, wrap", func(t *testing.T) {
83 files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "true")
84 b := hugolib.Test(t, files)
85
86 b.AssertFileContent("public/p1/index.html", "<p class=\"b\"><img src=\"/block.jpg\" alt=\"Block Image\"></p>")
87 })
88 }