djLint icon indicating copy to clipboard operation
djLint copied to clipboard

[BUG] [Formatter] Malformed formatted html containing jinja2 blocks and comments

Open ChristianF88 opened this issue 2 years ago • 1 comments

System Info

  • OS: Debian 11 & Manjaro
  • Python Version: python 10 & python 11
  • djLint Version: 1.19.15
  • template language: jinja2

Issue

I am working with jinja templates and the formatter seems to be having some issues with these templates. Some tags are not aligned, jinja comments are ignored.

How To Reproduce

I am running the command djlint template.html --reformat --profile=jinja to reformat.

Input and Output

{% ckan_extends %}
{% block info_module %}
    <section class="module module-narrow module-shallow">
        <h2 class="module-heading">
            <i class="fa fa-info-circle"></i> {{ _('What are datasets?') }}
        </h2>
        <div class="module-content">
            <p>
                {# Modification start; original below #}
                {#
      {% trans %}
      A CKAN Dataset is a collection of data resources (such as files),
      together with a description and other information, at a fixed URL.
      Datasets are what users see when searching for data.
      {% endtrans %}
   #}
                {% trans %}
                <p>Packages are the primary units of contents in the Eawag Research Data Platform.</p>
                <p>
                    A package is a collection of
                    <ol>
                        <li>
                            <i><b>resources</b></i> (files or links) and
                        </li>
                        <li>
                            <i><b>metadata</b></i>, such as abstract, keywords, author, ...
                        </li>
                    </ol>
                </p>
                <p>Packages are what users find when searching for data.</p>
                <p>Packages have a permanent URL.</p>
            {% endtrans %}
            {# Modification end #}
        </p>
    </div>
</section>
{% endblock %}

Desired

{% ckan_extends %}
{% block info_module %}
<section class="module module-narrow module-shallow">
    <h2 class="module-heading">
        <i class="fa fa-info-circle"></i> {{ _('What are datasets?') }}
    </h2>
    <div class="module-content">
        <p>
            {# Modification start; original below #}
            {#
              {% trans %}
              A CKAN Dataset is a collection of data resources (such as files),
              together with a description and other information, at a fixed URL.
              Datasets are what users see when searching for data.
              {% endtrans %}
            #}
            {% trans %}
            <p>Packages are the primary units of contents in the Eawag Research Data Platform.</p>
            <p>
                A package is a collection of
                <ol>
                    <li>
                        <i><b>resources</b></i> (files or links) and
                    </li>
                    <li>
                        <i><b>metadata</b></i>, such as abstract, keywords, author, ...
                    </li>
                </ol>
            </p>
            <p>Packages are what users find when searching for data.</p>
            <p>Packages have a permanent URL.</p>
            {% endtrans %}
            {# Modification end #}
        </p>
    </div>
</section>
{% endblock %}

ChristianF88 avatar Feb 27 '23 12:02 ChristianF88

Possibly a dupe of #557. Comments are currently excluded from the formatter.

christopherpickering avatar Feb 27 '23 15:02 christopherpickering