github.com/neohugo/neohugo@v0.123.8/tpl/tplimpl/render_hook_integration_test.go (about) 1 // Copyright 2024 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package tplimpl_test 15 16 import ( 17 "strings" 18 "testing" 19 20 "github.com/neohugo/neohugo/hugolib" 21 ) 22 23 func TestEmbeddedLinkRenderHook(t *testing.T) { 24 t.Parallel() 25 26 files := ` 27 -- hugo.toml -- 28 disableKinds = ['rss','sitemap','taxonomy','term'] 29 [markup.goldmark.renderHooks.link] 30 enableDefault = true 31 -- layouts/_default/list.html -- 32 {{ .Content }} 33 -- layouts/_default/single.html -- 34 {{ .Content }} 35 -- assets/a.txt -- 36 irrelevant 37 -- content/_index.md -- 38 --- 39 title: home 40 --- 41 -- content/s1/_index.md -- 42 --- 43 title: s1 44 --- 45 -- content/s1/p1.md -- 46 --- 47 title: s1/p1 48 --- 49 -- content/s1/p2/index.md -- 50 --- 51 title: s1/p2 52 --- 53 [500](a.txt) // global resource 54 [600](b.txt) // page resource 55 -- content/s1/p2/b.txt -- 56 irrelevant 57 -- content/s1/p3.md -- 58 --- 59 title: s1/p3 60 --- 61 // Remote 62 [10](https://a.org) 63 64 // fragment 65 [100](/#foo) 66 [110](#foo) 67 [120](p1#foo) 68 [130](p1/#foo) 69 70 // section page 71 [200](s1) 72 [210](/s1) 73 [220](../s1) 74 [230](s1/) 75 [240](/s1/) 76 [250](../s1/) 77 78 // regular page 79 [300](p1) 80 [310](/s1/p1) 81 [320](../s1/p1) 82 [330](p1/) 83 [340](/s1/p1/) 84 [350](../s1/p1/) 85 86 // leaf bundle 87 [400](p2) 88 [410](/s1/p2) 89 [420](../s1/p2) 90 [430](p2/) 91 [440](/s1/p2/) 92 [450](../s1/p2/) 93 ` 94 95 b := hugolib.Test(t, files) 96 97 b.AssertFileContent("public/s1/p3/index.html", 98 `<a href="https://a.org">10</a>`, 99 `<a href="/#foo">100</a>`, 100 `<a href="/s1/p3/#foo">110</a>`, 101 `<a href="/s1/p1/#foo">120</a>`, 102 `<a href="/s1/p1/#foo">130</a>`, 103 104 `<a href="/s1/">200</a>`, 105 `<a href="/s1/">210</a>`, 106 `<a href="/s1/">220</a>`, 107 `<a href="/s1/">230</a>`, 108 `<a href="/s1/">240</a>`, 109 `<a href="/s1/">250</a>`, 110 111 `<a href="/s1/p1/">300</a>`, 112 `<a href="/s1/p1/">310</a>`, 113 `<a href="/s1/p1/">320</a>`, 114 `<a href="/s1/p1/">330</a>`, 115 `<a href="/s1/p1/">340</a>`, 116 `<a href="/s1/p1/">350</a>`, 117 118 `<a href="/s1/p2/">400</a>`, 119 `<a href="/s1/p2/">410</a>`, 120 `<a href="/s1/p2/">420</a>`, 121 `<a href="/s1/p2/">430</a>`, 122 `<a href="/s1/p2/">440</a>`, 123 `<a href="/s1/p2/">450</a>`, 124 ) 125 126 b.AssertFileContent("public/s1/p2/index.html", 127 `<a href="/a.txt">500</a>`, 128 `<a href="/s1/p2/b.txt">600</a>`, 129 ) 130 } 131 132 // Issue 12203 133 func TestEmbeddedImageRenderHookMarkdownAttributes(t *testing.T) { 134 t.Parallel() 135 136 files := ` 137 -- config.toml -- 138 disableKinds = ['page','rss','section','sitemap','taxonomy','term'] 139 [markup.goldmark.parser] 140 wrapStandAloneImageWithinParagraph = false 141 [markup.goldmark.parser.attribute] 142 block = false 143 [markup.goldmark.renderHooks.image] 144 enableDefault = true 145 -- content/_index.md -- 146 ![alt](a.jpg) 147 {.foo #bar} 148 -- layouts/index.html -- 149 {{ .Content }} 150 ` 151 152 b := hugolib.Test(t, files) 153 b.AssertFileContent("public/index.html", `<img alt="alt" src="a.jpg">`) 154 155 files = strings.Replace(files, "block = false", "block = true", -1) 156 157 b = hugolib.Test(t, files) 158 b.AssertFileContent("public/index.html", `<img alt="alt" class="foo" id="bar" src="a.jpg">`) 159 }