技术栈里的每种语言都有格式化和检查工具,唯独 HTML 模板没有。普通 HTML 工具无法解析 {% %} 和 {{ }},模板引擎也不关心标记的排版。djLint 填补了这个盲区:既能格式化带模板语法的 HTML,也能检查常见错误,并为 Django、Jinja、Twig、Nunjucks、Handlebars、Liquid、Go 模板等提供预设配置。
pip install djlintmessy.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 %}
readme.md:
[](https://github.com/djlint/djlint)
在你项目中添加一个badge readme.rst:
.. image:: https://img.shields.io/badge/html%20style-djLint-blue.svg
:target: https://github.com/djlint/djlint
实际效果:
欢迎参与贡献。你可以提交一个包含新功能的PR,或者查看 issue 列表,并在你力所能及的地方提供帮助。