github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/safeHTML.md (about) 1 --- 2 title: safeHTML 3 # linktitle: 4 description: Declares a provided string as a "safe" HTML document to avoid escaping by Go templates. 5 godocref: https://golang.org/src/html/template/content.go?s=1374:1385#L25 6 date: 2017-02-01 7 publishdate: 2017-02-01 8 lastmod: 2017-02-01 9 categories: [functions] 10 menu: 11 docs: 12 parent: "functions" 13 keywords: [strings] 14 signature: ["safeHTML INPUT"] 15 workson: [] 16 hugoversion: 17 relatedfuncs: [] 18 deprecated: false 19 --- 20 21 It should not be used for HTML from a third-party, or HTML with unclosed tags or comments. 22 23 Given a site-wide [`config.toml`][config] with the following `copyright` value: 24 25 ``` 26 copyright = "© 2015 Jane Doe. <a href=\"http://creativecommons.org/licenses/by/4.0/\">Some rights reserved</a>." 27 ``` 28 29 `{{ .Site.Copyright | safeHTML }}` in a template would then output: 30 31 ``` 32 © 2015 Jane Doe. <a href="http://creativecommons.org/licenses/by/4.0/">Some rights reserved</a>. 33 ``` 34 35 However, without the `safeHTML` function, html/template assumes `.Site.Copyright` to be unsafe and therefore escapes all HTML tags and renders the whole string as plain text: 36 37 ``` 38 <p>© 2015 Jane Doe. <a href="http://creativecommons.org/licenses by/4.0/">Some rights reserved</a>.</p> 39 ``` 40 41 [config]: /getting-started/configuration/