djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
686 stars 84 forks source link

[BUG] [Formatter] Expression inside tag forces formatting to one-line #806

Open GPla opened 9 months ago

GPla commented 9 months ago

System Info

Issue

An expression {{ some_function(arg) }} inside a tag formats everything to a single-line, while without the attributes are split onto mutliple lines.

How To Reproduce

Create an issue.html.jinja2 and format it with djLint.

{# correctly formatted #}
<button class="btn p-1 m-1"
        id="a-very-very-very-long-id"
        aria-label="some button">Press me!</button>

{# forced to one-line when adding expression #}
<button class="btn p-1 m-1" id="a-very-very-very-long-id" aria-label="some button" {{ attributes(attr) }}>Press me!
</button>
nitsujri commented 7 months ago

Similarly, I have

              <a
                class="dropdown-item{% if item.class %}{{item.class}}{% endif %}"
                href="{{ item.url }}"
                {% if item.html_attrs %} {% for attr, value in item.html_attrs.items %}{{ attr }}="{{ value }}"{% endfor %} {% endif %}
                {% if item.target %}target="{{ item.target }}"{% endif %}
                {% if item.confirm %}onclick="return confirm('{{ item.confirm }}');"{% endif %}
              >
                <i class="dropdown-item-icon"></i>{{ item.label }}
              </a>

gets auto formatted to:

              <a class="dropdown-item{% if item.class %}{{ item.class }}{% endif %}" href="{{ item.url }}" {% if item.html_attrs %} {% for attr, value in item.html_attrs.items %}{{ attr }}="{{ value }}"{% endfor %} {% endif %} {% if item.target %}target="{{ item.target }}"{% endif %} {% if item.confirm %}onclick="return confirm('{{ item.confirm }}');"{% endif %}>
                <i class="dropdown-item-icon"></i>{{ item.label }}
              </a>