This plugin makes two passes when formatting a HubL document. The first pass utilizes Prettier's built in HTML formatter which has it's own specific formatting rules. Two notables rules are:
- Self closing tags will contain a
/
:<img src="" />
- HTML tags may be broken up in order to preserve whitespace:
<a class="blog-post__tag-link" href="{{ url }}" rel="tag"
>{{ tag.name }}</a
>
- The
body
or children of a block tag will be generally be indented one level deeper - No specific quote type is enforced. However, quotes inside of quotes will be adjusted or escaped as needed
{% set var = "some string" %}
May be printed on a single line if it will fit
{% if true %}Hello{% endif %}
{% if condition %}
[indented content]
{% elif condition %}
[indented content]
{% else %}
[indented content]
{% endif %}
{% unless condition %}
[indented content]
{% endunless %}
{% raw %}
[preserved content]
{% endraw %}
{% for item in list %}
[indented content]
{% endfor %}
{% macro macro_name(list, of, params) %}
[indented content]
{% endmacro %}
{% extends "path/to/file" %}
{% include "path/to/file" %}
{% import "path/to/file" %}
{# import variable from 'path/to/file' #}
{% call macro_name("string") %}
[indented content]
{% endcall %}
{% do variable.method() %}
{% block name %}
[indented content]
{% endblock name %}
foo ~ bar
foo and bar
Note: &&
is converted to and
foor or bar
Note: ||
is converted to or
foo is string_containing(“bar”)
Note: string_containing “bar”
will be converted to string_containing(“bar”)
condition ? foo : bar
foo if condition else bar
foo / bar
foo * bar
foo % bar
foo ** bar
-variable
foo - bar
foo + bar
foo in bar
(foo + bar)
|filter
|filter(list, of, params)
function(list, of, params)
left is not right
not variable
variable.property
variable[symbol]
Note: When the key is string (variable['property']
) it will be converted to variable.property
{% tag 'name' foo="bar" %}
{% tag 'name'
foo="bar",
bar="foo" %}
{% longerTag 'name'
item1=true,
item2="foo",
item3=bar %}
Note: When there are 2 or more keyword arguments, they will be displayed on multiple lines
[ "list", "of", "items"]
[
"long",
"list",
"of",
"items"
]
{ a: true, b: false }
{
item1: true,
item2: false
item3: 100
}
key as value
symbol
"string"