Files
liquidjs/docs/source/tutorials/escaping.md
ed15a52c26 docs: revisit wording & style for liquidjs.com (#906)
* docs: polish theme, playground, and reference pages

Improve readability of the docs site with updated light/dark tokens, shared
code-block styling, and playground editors that follow system color scheme.
Skip CookieHub on localhost, serve the browser bundle from theme source, and
use backtick titles on filter/tag reference pages for consistent navigation.

Co-authored-by: Cursor <[email protected]>

* docs: highlight npx in bash blocks and polish English copy

Use Prism insertBefore for CLI commands like npx, tighten tutorial and reference wording, and keep YAML titles free of backticks so sidebar and page headings stay correct.

Co-authored-by: Cursor <[email protected]>

* docs: restore lowercase filter and tag titles

Titles should match actual filter/tag identifiers (e.g. abs, append), not capitalized English labels.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Cursor <[email protected]>
2026-06-08 00:26:52 +08:00

1.9 KiB

title
title
Escaping

Escaping is important in all languages, including LiquidJS. Escaping has two different meanings for a template engine:

  1. Escaping for the output, i.e. HTML escape. Used to escape HTML special characters so the output will not break HTML structures, aka HTML safe.
  2. Escaping for the language itself, i.e. Liquid escape. Used to output strings that are considered special in the Liquid language. This is useful when you're writing an article in a Liquid template to introduce the Liquid language.

HTML Escape

By default output is not escaped. While you can use escape filter for this:

Input

{{ "1 < 2" | escape }}

Output

1 &lt; 2

There's also escape_once, newline_to_br, strip_html filters for you to fine tune your output.

In cases where variables are mostly not trusted, outputEscape can be set to "escape" to apply escape by default. In this case, when you need some output not to be escaped, raw filter can be used:

Input

{{ "1 < 2" }}
{{ "<button>OK</button>" | raw }}

Output

1 &lt; 2
<button>OK</button>

Liquid Escape

To disable Liquid language and output strings like {{ and {%, the raw tag can be used.

Input

{% raw %}
  In LiquidJS, {{ this | escape }} will be HTML-escaped, but
  {{{ that }}} will not.
{% endraw %}

Output

In LiquidJS, {{ this | escape }} will be HTML-escaped, but
{{{ that }}} will not.

Within string literals in a LiquidJS template, \ can be used to escape special characters in string syntax. For example:

Input

{{ "\"" }}

Output

"