Analizza e formatta i template HTML

Ogni linguaggio del tuo stack ha un formattatore e un linter, tranne i template HTML. Gli strumenti HTML generici non sanno interpretare {% %} e {{ }}, e ai motori di template non importa che aspetto abbia il markup che li circonda. djLint riformatta l'HTML ricco di sintassi di template e lo analizza alla ricerca degli errori più comuni, con profili per Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, template Go e altri ancora.

uv tool install djlint
pip install djlint

trova il tuo linguaggio di template preferito!

Prima e dopo

messy.html
{% block content %}
<SECTION class="posts">


<h2>Latest posts</h2>
{%if posts%}
<ul>
{% for post in posts %}
<li>
<a href="{% url 'post' post.slug %}" class="post-link {%if post.featured%}is-featured{%endif%}" data-analytics-id="post-{{post.id}}" aria-label="Read {{post.title}}">{{post.title|title}}</a>
</li>
{% endfor %}
</ul>
{%else%}
<p>No posts yet.</p>
{%endif%}
</SECTION>
{% endblock %}
$ djlint messy.html --reformat --single-attribute-per-line
{% block content %}
    <section class="posts">
        <h2>Latest posts</h2>
        {% if posts %}
            <ul>
                {% for post in posts %}
                    <li>
                        <a
                            href="{% url 'post' post.slug %}"
                            class="post-link {% if post.featured %}is-featured{% endif %}"
                            data-analytics-id="post-{{ post.id }}"
                            aria-label="Read {{ post.title }}"
                        >{{ post.title|title }}</a>
                    </li>
                {% endfor %}
            </ul>
        {% else %}
            <p>No posts yet.</p>
        {% endif %}
    </section>
{% endblock %}

Mostra il tuo formato!

Ecco come appare:

html style: djLint

Aggiungi un badge ai tuoi progetti:

[![Code style: djLint](https://img.shields.io/badge/html%20style-djLint-blue.svg)](https://github.com/djlint/djlint)
.. image:: https://img.shields.io/badge/html%20style-djLint-blue.svg
   :target: https://github.com/djlint/djlint

Contribuire

I contributi sono benvenuti. Invia una pr con una nuova funzionalità, oppure consulta l'elenco delle issue e dai una mano dove puoi.

GitHub