Skip to content

Conformance Examples 0.1.0 — Transforms: transform-escape_once

escape_once-all-metacharacters

With no existing entities, encodes &, <, >, double-quote, and single-quote like escape. Uses {{{ }}} so the renderer does not re-escape the transform's output.

Template

{{{ html | escape_once }}}

Context

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

Output

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

escape_once-preserves-existing-entities

An ampersand already beginning a named or numeric entity is left untouched, while bare metacharacters are encoded.

Template

{{{ html | escape_once }}}

Context

{
    "html": "&amp; < &#x27;"
}

Output

&amp; &lt; &#x27;

escape_once-bare-ampersand

An ampersand not followed by a valid entity is encoded.

Template

{{{ html | escape_once }}}

Context

{
    "html": "Tom & Jerry"
}

Output

Tom &amp; Jerry

escape_once-idempotent-hex-entity

Applying escape_once to a string already containing its own ' output does not re-escape the entity's ampersand.

Template

{{{ html | escape_once | escape_once }}}

Context

{
    "html": "it's"
}

Output

it&#x27;s

Source fixture: transforms/transform-escape_once.json