| 1 |
--- |
| 2 |
title: transform.HTMLUnescape |
| 3 |
description: Returns the given string, replacing each HTML entity with its corresponding character. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [htmlUnescape] |
| 9 |
returnType: string |
| 10 |
signatures: [transform.HTMLUnescape INPUT] |
| 11 |
aliases: [/functions/htmlunescape] |
| 12 |
--- |
| 13 |
|
| 14 |
The `transform.HTMLUnescape` function replaces [HTML entities][] with their corresponding characters. |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ htmlUnescape "Lilo & Stitch" }} → Lilo & Stitch |
| 18 |
{{ htmlUnescape "7 > 6" }} → 7 > 6 |
| 19 |
``` |
| 20 |
|
| 21 |
In most contexts Go's [`html/template`][] package will escape special characters. To bypass this behavior, pass the unescaped string through the [`safe.HTML`][] function. |
| 22 |
|
| 23 |
```go-html-template |
| 24 |
{{ htmlUnescape "Lilo & Stitch" | safeHTML }} |
| 25 |
``` |
| 26 |
|
| 27 |
[HTML entities]: https://developer.mozilla.org/en-US/docs/Glossary/Entity |
| 28 |
[`html/template`]: https://pkg.go.dev/html/template |
| 29 |
[`safe.HTML`]: /functions/safe/html/ |