adamchainz/djade

Blank line between different tags (extends, load, block)

Closed this issue · 1 comments

Package Version

1.2.0

Description

Hi @adamchainz,

Congratulations on your work on this fantastic library. I started using it this week and I am really happy!

However, I think I have found a Django template where I have some issues:

This is my input:

{% extends "..." %} {% load widget_tweaks %} {% load i18n %} {% load allauth account %} {% block head_title %} {% trans "Sign Up" %} {% endblock head_title %} {% block form_title %} ... {% endblock form_title %} {% block form %}

And this is my output using djade:

{% extends "..." %} {% load account allauth i18n widget_tweaks %}{% block head_title %} {% translate "Sign Up" %}{% endblock %}

{% block form_title %} ...{% endblock %}

{% block form %}

I found that djade does a lot of things really well:

  • Merge consecutive {% load %} tags.
  • No labels in {% endblock %} tags on the same line as their opening {% block %} tag:
  • trans -> translate

However, in the output I would expect something like this:

{% extends "..." %}
{% load account allauth i18n widget_tweaks %}
{% block head_title %}
    {% translate "Sign Up" %}
{% endblock head_title %}

{% block form_title %}
    ...
{% endblock form_title %}

{% block form %}

The input in one line are produced by prettier. I know your recommendation to use djade before prettier, but for me this is even worse, because prettier break all the good work of djade, not ignoring the django tags :(

So Prettier is merging loads of tags onto one line, and you want Djade to undo that? I don't think that's within scope for Djade. Prettier's whitespace changes aren't 100% safe to make and thus not safe to "undo".

#59 will implement some more tidying of top-level tags, which will make your template a bit more tolerable, but not much.

The real answer is to not apply Prettier to your template files, at least in a mode that merges all tags onto one line like that. (Were you using the prettier-django plugin?)