New lines get removed when saving HTML files
I use Prettier. I've tried Django extension, Better Jinja and Django Support in VS Code, new lines get removed on save for some reason. This code:
{% with available=terms.available|date:"Y-m-d" created_at=listing.created_at|date:"Y-m-d" %}
{% if terms.available == listing.created_at %}
Odmah
{% else %}
{{terms.available | date:"d.m.Y"}}
{% endif %}
{% endwith %}
turns into this on save:
{% with available=terms.available|date:"Y-m-d"
created_at=listing.created_at|date:"Y-m-d" %} {% if terms.available ==
listing.created_at %} Odmah {% else %} {{terms.available |
date:"d.m.Y"}} {% endif %} {% endwith %}
which also causes TemplateSyntaxError. How do I keep new lines intact?
Try adding this to the settings
"html.format.templating": true,
If you are using Prettier, https://github.com/junstyle/prettier-plugin-django might solve this.
How do I use the extension with djlint?
EDIT: I did this:
"[django-html][html]": {
"editor.defaultFormatter": "monosans.djlint"
}
That should work. Did it?
And you don't even need [django-html]
That should work. Did it?
And you don't even need
[django-html]
It worked. I had to make djlint be a formatter for Django-Html, because prettier doesn't work well with template engines.
I meant, this would also do the work
"[html]": {
"editor.defaultFormatter": "monosans.djlint"
}