davidodenwald / prettier-plugin-jinja-template

Formatter plugin for jinja2 template files.
MIT License
94 stars 11 forks source link

Multiline Jinja content loses indentation and line breaks #13

Closed hyvyys closed 6 months ago

hyvyys commented 1 year ago

The following:

{% set dict = {
    "item": "value",
    "list": [
      "value",
      "value",
      "value",
    ],
    "item": "value",
} %}

get unnecessarily reformatted to this:

{%
  set dict = {
  "item": "value",
  "list": [
  "value",
  "value",
  "value",
  ],
  "item": "value",
  }
%}
davidodenwald commented 1 year ago

Code gets indented if a statement of expression spans multiple lines. But because this plugin doesn't parse and format jinja/python code there is no way of knowing how to further indent the content of the block. This results in the whole block being indented to the same level.

I would be open to add this feature if there was a good javascript jinja parser.

hyvyys commented 1 year ago

If that’s feasible at all, then the simplest solution would be to leave any Jinja content as-is, with the exception of indenting/dedenting everything as a whole as needed. (Perhaps this could be an opt-in feature?)

davidodenwald commented 6 months ago

Fixes by v1.4.0