René Jahn
René Jahn

Reputation: 1213

Visual Studio Code and Flask Jinja Templates

I have recently switched to Visual Studio Code (previously used PyCharm) and am now facing a formatting problem.

With the following example html:

{% extends 'base.html' %} 
{% block body %} 
{{ super() }}
  <div>Something</div>
{% endblock%}

after saving (I have turned on formatOnSave) I get the following:

{% extends 'base.html' %}{% block body %}{{ super() }}
<div>Something</div>{% endblock%}

I am using the editorconfig plugin and have stayed with the default user settings.

How can I configure VSC to not force Jinja blocks to be on a single line?

Upvotes: 11

Views: 12257

Answers (2)

jacek2v
jacek2v

Reputation: 590

I have a temporary solution for that. Use Better Jinja extension and add to jinja2 files .html.j2 extension. You lose build-in HTML formatting but preserve jinja2 syntax :)

Upvotes: 1

Jakub Krzesłowski
Jakub Krzesłowski

Reputation: 51

There's a known issue with trailing spaces.

You might try another extension dedicated to jinja: https://github.com/wholroyd/vscode-jinja

Upvotes: 2

Related Questions