rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Spacing within tags #112

Closed korverdev closed 6 months ago

korverdev commented 8 months ago

This is more of a feature request, but I'd love if this project standardized spacing within tags as well. For example, the following is currently unchanged:

{% if log.severity == 0%}

It would be great if this could be formatted automatically to mirror Django's examples:

{% if log.severity == 0% }
JaapJoris commented 6 months ago

While I understand and appreciate your request, I'm going to be very harsh and close it as WONTFIX. The goal of DjHTML has always been limited to indenting and not formatting templates. From the README:

DjHTML is an indenter and not a formatter: it will only add/remove whitespace at the beginning of lines

korverdev commented 6 months ago

Makes total sense. Sorry I somehow overlooked that and thanks for the explanation.

balazs-endresz commented 4 months ago

Adding the following to .pre-commit-config.yaml seems to be able to sort this out as well. I've tested on Ubuntu, Command Prompt, and PowerShell. I think it's supposed to work on MacOS too without installing anything extra.

  - repo: local
    hooks:
      - id: template-spaces
        name: template-spaces
        entry: perl -pi -e "s/{%\s*/{% /g; s/\s*%}/ %}/g; s/{{\s*/{{ /g; s/\s*}}/ }}/g"
        language: system
        files: templates/.+\.(txt|html)$