hugo/docs/content/en/functions/transform/XMLEscape.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.2 KiB

title description categories keywords action
transform.XMLEscape Returns the given string, removing disallowed characters then escaping the result to its XML equivalent.
aliases related returnType signatures
string
transform.XMLEscape INPUT

{{< new-in 0.121.0 >}}

The transform.XMLEscape function removes disallowed characters as defined in the XML specification, then escapes the result by replacing the following characters with HTML entities:

  • "&#34;
  • '&#39;
  • &&amp;
  • <&lt;
  • >&gt;
  • \t&#x9;
  • \n&#xA;
  • \r&#xD;

For example:

{{ transform.XMLEscape "<p>abc</p>" }}&lt;p&gt;abc&lt;/p&gt;

When using transform.XMLEscape in a template rendered by Go's html/template package, declare the string to be safe HTML to avoid double escaping. For example, in an RSS template:

{{< code file="layouts/_default/rss.xml" >}} {{ .Summary | transform.XMLEscape | safeHTML }} {{< /code >}}