Page MenuHome

Reindent templates taking Django tags into account
ClosedPublic

Authored by Anna Sirota (railla) on May 27 2021, 12:32 PM.

Details

Summary

Reindents all HTML templates using https://github.com/sobolevn/djhtml and tabwidth of 2 spaces and adds djhtml to pre-commit hooks. This makes templates overall more readable and makes it easier to keep track of template's logic.
The downside is that it produces HTML indented in a way that it doesn't make sense: Django tags will produce additional indentation levels where none exist from the point of view of plain HTML. This isn't really an issue though, no one ever looks at the produced HTML other than from the browser's devtools, which reindent it anyway.

It's also important to keep in mind that "overhanging " closing tags break the formatters that do this kind of indenting. For examples:

Not OK ✖ 🔥

{% comment %}<div>....
...
</div>{% endcomment %}

OK 🆗

{% comment %}
  <div>....
  ...
  </div>
{% endcomment %}

Same for HTML tags:

Not OK ✖🔥

<p>Lorem impsum .........<a
    href="">Link</a></p>

OK 🆗

<p>Lorem impsum .........
  <a href="">Link</a>
</p>

Diff Detail