Analiza y formatea plantillas HTML

Cada lenguaje de tu stack tiene un formateador y un linter, salvo las plantillas HTML. Las herramientas HTML genéricas no saben interpretar {% %} ni {{ }}, y a los motores de plantillas no les importa cómo se ve el marcado que las rodea. djLint reformatea el HTML cargado de sintaxis de plantillas y lo analiza en busca de errores comunes, con perfiles para Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, plantillas de Go y más.

uv tool install djlint
pip install djlint

¡encuentra tu lenguaje de plantillas favorito!

Antes y después

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 %}

¡Muestra tu formato!

Se ve así:

html style: djLint

Añade una insignia a tus proyectos:

[![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

Contribuir

Las contribuciones son bienvenidas. Envía una pull request con una nueva funcionalidad, o consulta la lista de issues y ayuda en lo que puedas.

GitHub