This repository is a reproduction of the issue described in prettier-plugin-jinja-template#8.
-
Clone this repository
-
Run
yarn install
oryarn
Note
If you don't have
yarn
, you can install it withcorepack enable
if nodejs version is>= 14.19.0
or>= 16.9.0
-
Preview the input file before formatting:
$ cat unformatted.jinja {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} <div> {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} </div>
-
Run
yarn lint
to preview formatted output❯ yarn lint yarn run v1.22.19 $ prettier *.jinja {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} <div> {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} </div> ✨ Done in 0.52s.
-
Run
yarn lint@fix
to format the input file:❯ yarn lint@fix yarn run v1.22.19 $ prettier --write *.jinja unformatted.jinja 19ms ✨ Done in 0.56s.
-
Preview formatted output:
❯ cat unformatted.jinja {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} <div> {% with text='text', version=1 %} {% include 'directory/template.jinja2' %} {% endwith %} </div>
Expected output looks like this:
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}
<div>
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}
</div>
Actual output is:
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}
<div>
{% with text='text', version=1 %}
{% include 'directory/template.jinja2' %}
{% endwith %}
</div>