Zum Inhalt springen

HTML-Templates linten und formatieren

Allgemeine HTML-Tools können {% %} und {{ }} nicht parsen, und Template-Engines ist es egal, wie das Markup um sie herum aussieht. djLint formatiert HTML voller Template-Syntax neu und prüft es per Linting auf typische Fehler, mit Profilen für Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, Go-Templates und mehr. Es läuft auf der Kommandozeile, als pre-commit-Hook und als Sprachserver in Ihrem Editor.

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

messy.html10 ProblemeKeine Probleme
{% 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

Ein Profil für Ihre Template-Sprache

Badge

So sieht es aus:html style: djLint

Fügen Sie Ihren Projekten ein Badge hinzu:

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

Mitwirken

Beiträge sind willkommen. Suchen Sie sich ein Issue aus, an dem Sie arbeiten möchten, oder öffnen Sie einen Pull Request mit einem Fix oder einem neuen Feature.

GitHub

djLint wurde von Christopher Pickering für die Atlas-Projekte entwickelt. Heute pflegen es monosans und alle, die beitragen.