Preserve HTML Text for link render hooks

The context now have two text methods:

* Text - rendered
* PlainText

Fixes #6629
This commit is contained in:
Bjørn Erik Pedersen
2019-12-18 17:23:09 +01:00
parent 1b785a7a6d
commit 00954c5d1f
5 changed files with 79 additions and 12 deletions

View File

@@ -213,6 +213,37 @@ P3: <p>P3. xml-link: https://www.example.org|</p>
}
// https://github.com/gohugoio/hugo/issues/6629
func TestRenderLinkWithMarkupInText(t *testing.T) {
b := newTestSitesBuilder(t)
b.WithTemplates("index.html", `
{{ $p := site.GetPage "p1.md" }}
P1: {{ $p.Content }}
`,
"_default/_markup/render-link.html", `html-link: {{ .Destination | safeURL }}|Text: {{ .Text | safeHTML }}|Plain: {{ .PlainText | safeHTML }}`,
)
b.WithContent("p1.md", `---
title: "p1"
---
START: [**should be bold**](https://gohugo.io)END
Some regular **markup**.
`)
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", `
P1: <p>START: html-link: https://gohugo.io|Text: <strong>should be bold</strong>|Plain: should be boldEND</p>
<p>Some regular <strong>markup</strong>.</p>
`)
}
func TestRenderString(t *testing.T) {
b := newTestSitesBuilder(t)