Pular para o conteúdo

Lint e formatação de templates HTML

Ferramentas genéricas de HTML não conseguem interpretar {% %} e {{ }}, e os motores de templates não se importam com a aparência da marcação ao redor. O djLint reformata HTML repleto de sintaxe de template e faz o lint em busca de erros comuns, com perfis para Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, templates Go e muito mais. Funciona na linha de comando, como hook do pre-commit e como servidor de linguagem no seu editor.

uv tool install djlint
pip install djlint
npm i -g djlint

messy.html10 problemasNenhum problema
{% block content %}<SECTION H009 Tag names should be lowercase. class='posts' H008 Attributes should be double quoted.> H014 Found extra blank lines.<h2>Latest posts</h2>{%if posts%} T001 Variables should be wrapped in a whitespace.<ul>{% for post in posts %}<li><a href="{% url 'post' post.slug %}" class='post-link' H008 Attributes should be double quoted. aria-label="Read {{post.title}}" T001 Variables should be wrapped in a whitespace.>{{post.title}} T001 Variables should be wrapped in a whitespace.</a></li>{% endfor %}</ul>{%else%} T001 Variables should be wrapped in a whitespace.<p>No posts yet.</p>{%endif%} T001 Variables should be wrapped in a whitespace.</SECTION H009 Tag names should be lowercase.>{% endblock %}
{% 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"                           aria-label="Read {{ post.title }}">{{ post.title }}</a>                    </li>                {% endfor %}            </ul>        {% else %}            <p>No posts yet.</p>        {% endif %}    </section>{% endblock %}
{% 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"                            aria-label="Read {{ post.title }}"                        >{{ post.title }}</a>                    </li>                {% endfor %}            </ul>        {% else %}            <p>No posts yet.</p>        {% endif %}    </section>{% endblock %}
djlint messy.html --reformat

Um perfil para a sua linguagem de template

Selo

Fica assim:html style: djLint

Adicione um selo aos seus projetos:

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

Como contribuir

Contribuições são bem-vindas. Escolha uma issue para trabalhar ou abra um pull request com uma correção ou um novo recurso.

GitHub

O djLint foi criado por Christopher Pickering para os projetos Atlas. Hoje ele é mantido por monosans e todas as pessoas que contribuem.