Skip to content

Conformance Examples 0.1.0 — Transforms: transform-escape

escape-all-metacharacters

Encodes &, <, >, double-quote, and single-quote as HTML entities. Uses {{{ }}} so the renderer does not re-escape the transform's output.

Template

{{{ html | escape }}}

Context

{
    "html": "<b>A & 'B' \"C\"</b>"
}

Output

&lt;b&gt;A &amp; &#x27;B&#x27; &quot;C&quot;&lt;/b&gt;

escape-double-escapes-existing-entity

Unlike escape_once, escape re-encodes the ampersand of an existing entity.

Template

{{{ html | escape }}}

Context

{
    "html": "&amp;"
}

Output

&amp;amp;

escape-no-special-characters

Plain text without metacharacters is returned unchanged.

Template

{{{ html | escape }}}

Context

{
    "html": "hello world"
}

Output

hello world

Source fixture: transforms/transform-escape.json