djlint 1.42.1 → 1.42.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -30
- package/package.json +17 -7
package/README.md
CHANGED
|
@@ -1,46 +1,86 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
2
|
<br>
|
|
3
|
-
<a href="https://
|
|
3
|
+
<a href="https://djlint.com"><img src="https://raw.githubusercontent.com/djlint/djLint/master/docs/src/static/img/icon.png" alt="djLint Logo" width="270"></a>
|
|
4
4
|
<br>
|
|
5
5
|
</h1>
|
|
6
6
|
<h4 align="center">The missing formatter and linter for HTML templates.</h4>
|
|
7
7
|
|
|
8
8
|
<p align="center">
|
|
9
|
-
|
|
10
|
-
<a href="https://discord.gg/taghAqebzU">
|
|
11
|
-
<img src="https://badgen.net/discord/online-members/taghAqebzU?icon=discord&label" alt="Discord Chat">
|
|
12
|
-
</a>
|
|
13
|
-
</p>
|
|
14
|
-
<p align="center">
|
|
15
|
-
<a href="https://pepy.tech/project/djlint">
|
|
9
|
+
<a href="https://pypi.org/project/djlint/">
|
|
16
10
|
<img src="https://pepy.tech/badge/djlint" alt="Downloads">
|
|
17
11
|
</a>
|
|
18
|
-
<a href="https://
|
|
19
|
-
|
|
20
|
-
</a>
|
|
21
|
-
<a href="https://pypi.org/project/djlint/">
|
|
22
|
-
<img src="https://img.shields.io/pypi/v/djlint" alt="Pypi Download">
|
|
12
|
+
<a href="https://discord.gg/taghAqebzU">
|
|
13
|
+
<img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fdiscord.com%2Fapi%2Fv10%2Finvites%2FtaghAqebzU%3Fwith_counts%3Dtrue&query=%24.approximate_presence_count&label=discord&suffix=%20online&logo=discord&logoColor=white&color=5865F2" alt="Discord">
|
|
23
14
|
</a>
|
|
24
15
|
</p>
|
|
25
16
|
|
|
26
|
-
<h4 align="center"><a href="https://
|
|
17
|
+
<h4 align="center"><a href="https://djlint.com">How to use</a> • <a href="https://djlint.com/ru/">Как пользоваться</a> • <a href="https://djlint.com/fr/">Utilisation</a> • <a href="https://djlint.com/zh/">如何使用</a></h4>
|
|
27
18
|
<h4 align="center">What lang are you using?</h4>
|
|
28
19
|
|
|
29
20
|
<p align="center">
|
|
30
|
-
<a href="https://djlint.com/docs/languages/django/">Django</a> • <a href="https://djlint.com/docs/languages/jinja/">Jinja</a> • <a href="https://djlint.com/docs/languages/
|
|
31
|
-
</p>
|
|
32
|
-
|
|
33
|
-
<p align="center">
|
|
34
|
-
<img src="https://github.com/djlint/djLint/blob/aa9097660d4a2e840450de5456f656c42bc7dd34/docs/src/static/img/demo-min.gif" alt="demo" width="600">
|
|
21
|
+
<a href="https://djlint.com/docs/languages/django/">Django</a> • <a href="https://djlint.com/docs/languages/jinja/">Jinja</a> • <a href="https://djlint.com/docs/languages/twig/">Twig</a> • <a href="https://djlint.com/docs/languages/nunjucks/">Nunjucks</a> • <a href="https://djlint.com/docs/languages/handlebars/">Handlebars</a> • <a href="https://djlint.com/docs/languages/liquid/">Liquid</a> • <a href="https://djlint.com/docs/languages/golang/">Go templates</a> • <a href="https://djlint.com/docs/languages/angular/">Angular</a> • <a href="https://djlint.com/docs/languages/mustache/">Mustache</a> • <a href="https://djlint.com/docs/languages/tera/">Tera</a> • <a href="https://djlint.com/docs/languages/askama/">Askama</a>
|
|
35
22
|
</p>
|
|
36
23
|
|
|
37
24
|
## 🤔 For What?
|
|
38
25
|
|
|
39
|
-
|
|
26
|
+
Every language in your stack has a formatter and a linter. HTML templates are the exception. Generic HTML tools can't parse `{% %}` and `{{ }}`, and template engines don't care what the markup around them looks like. Templates end up in a tooling blind spot: drifting indentation, mismatched tags and inconsistent spacing that survive every code review.
|
|
27
|
+
|
|
28
|
+
djLint covers that blind spot. It understands HTML _and_ the template syntax inside it, with profiles for Django, Jinja, Twig, Nunjucks, Handlebars, Liquid, Go templates and more.
|
|
29
|
+
|
|
30
|
+
Take a template only its author could love:
|
|
31
|
+
|
|
32
|
+
```django
|
|
33
|
+
{% block content %}
|
|
34
|
+
<SECTION class="posts">
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<h2>Latest posts</h2>
|
|
38
|
+
{%if posts%}
|
|
39
|
+
<ul>
|
|
40
|
+
{% for post in posts %}
|
|
41
|
+
<li>
|
|
42
|
+
<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>
|
|
43
|
+
</li>
|
|
44
|
+
{% endfor %}
|
|
45
|
+
</ul>
|
|
46
|
+
{%else%}
|
|
47
|
+
<p>No posts yet.</p>
|
|
48
|
+
{%endif%}
|
|
49
|
+
</SECTION>
|
|
50
|
+
{% endblock %}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
One `djlint --reformat --single-attribute-per-line` later:
|
|
54
|
+
|
|
55
|
+
```django
|
|
56
|
+
{% block content %}
|
|
57
|
+
<section class="posts">
|
|
58
|
+
<h2>Latest posts</h2>
|
|
59
|
+
{% if posts %}
|
|
60
|
+
<ul>
|
|
61
|
+
{% for post in posts %}
|
|
62
|
+
<li>
|
|
63
|
+
<a
|
|
64
|
+
href="{% url 'post' post.slug %}"
|
|
65
|
+
class="post-link {% if post.featured %}is-featured{% endif %}"
|
|
66
|
+
data-analytics-id="post-{{ post.id }}"
|
|
67
|
+
aria-label="Read {{ post.title }}"
|
|
68
|
+
>{{ post.title|title }}</a>
|
|
69
|
+
</li>
|
|
70
|
+
{% endfor %}
|
|
71
|
+
</ul>
|
|
72
|
+
{% else %}
|
|
73
|
+
<p>No posts yet.</p>
|
|
74
|
+
{% endif %}
|
|
75
|
+
</section>
|
|
76
|
+
{% endblock %}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
One command rebuilt the indentation, fixed the tag case, split the long tag into one attribute per line, normalized the template tags and collapsed stray blank lines.
|
|
40
80
|
|
|
41
|
-
|
|
81
|
+
And the linter catches what formatting can't fix: orphan tags, missing `alt` attributes, hard-coded URLs and dozens of other checks.
|
|
42
82
|
|
|
43
|
-
**
|
|
83
|
+
**[Try it on your own templates in the online playground →](https://djlint.com/demo/)**
|
|
44
84
|
|
|
45
85
|
## ✨ How?
|
|
46
86
|
|
|
@@ -77,19 +117,25 @@ npm i djlint
|
|
|
77
117
|
Lint your project
|
|
78
118
|
|
|
79
119
|
```bash
|
|
80
|
-
djlint . --
|
|
120
|
+
djlint . --lint
|
|
81
121
|
```
|
|
82
122
|
|
|
83
123
|
Check your format
|
|
84
124
|
|
|
85
125
|
```bash
|
|
86
|
-
djlint . --
|
|
126
|
+
djlint . --check
|
|
87
127
|
```
|
|
88
128
|
|
|
89
129
|
Fix my format!
|
|
90
130
|
|
|
91
131
|
```bash
|
|
92
|
-
djlint . --
|
|
132
|
+
djlint . --reformat --single-attribute-per-line
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Set a `--profile` to enable the rules and formatting of your template engine
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
djlint . --reformat --single-attribute-per-line --profile=django
|
|
93
139
|
```
|
|
94
140
|
|
|
95
141
|
Or use `pre-commit` to reformat, then lint!
|
|
@@ -97,25 +143,30 @@ Or use `pre-commit` to reformat, then lint!
|
|
|
97
143
|
```yaml
|
|
98
144
|
repos:
|
|
99
145
|
- repo: https://github.com/djlint/djLint
|
|
100
|
-
rev: v1.
|
|
146
|
+
rev: v1.42.1 # use latest version instead
|
|
101
147
|
hooks:
|
|
102
148
|
- id: djlint-reformat
|
|
103
149
|
- id: djlint
|
|
104
150
|
```
|
|
105
151
|
|
|
152
|
+
## 🧩 Editors
|
|
153
|
+
|
|
154
|
+
- **VS Code**: install the [djLint extension](https://marketplace.visualstudio.com/items?itemName=monosans.djlint) (also on [Open VSX](https://open-vsx.org/extension/monosans/djlint)).
|
|
155
|
+
- **neovim, Sublime Text, MegaLinter and more**: see the [integrations docs](https://djlint.com/docs/integrations/).
|
|
156
|
+
|
|
106
157
|
## 💙 Like it?
|
|
107
158
|
|
|
108
159
|
Add a badge to your projects `readme.md`:
|
|
109
160
|
|
|
110
161
|
```md
|
|
111
|
-
[](https://
|
|
162
|
+
[](https://djlint.com)
|
|
112
163
|
```
|
|
113
164
|
|
|
114
165
|
Add a badge to your `readme.rst`:
|
|
115
166
|
|
|
116
167
|
```rst
|
|
117
168
|
.. image:: https://img.shields.io/badge/html%20style-djlint-blue.svg
|
|
118
|
-
:target: https://
|
|
169
|
+
:target: https://djlint.com
|
|
119
170
|
```
|
|
120
171
|
|
|
121
172
|
Looks like this:
|
|
@@ -126,9 +177,17 @@ Looks like this:
|
|
|
126
177
|
|
|
127
178
|
Yes!
|
|
128
179
|
|
|
129
|
-
_Would you like to add a rule to the linter?_ Take a look at the [linter docs](https://djlint.com/docs/linter/) and [
|
|
180
|
+
_Would you like to add a rule to the linter?_ Take a look at the [linter docs](https://djlint.com/docs/linter/) and the [rule definitions](https://github.com/djlint/djLint/blob/master/src/djlint/rules.yaml).
|
|
181
|
+
|
|
182
|
+
Local setup takes two commands:
|
|
130
183
|
|
|
131
|
-
|
|
184
|
+
```bash
|
|
185
|
+
# install uv first: https://docs.astral.sh/uv/getting-started/installation/
|
|
186
|
+
uv sync
|
|
187
|
+
|
|
188
|
+
# run the test suite
|
|
189
|
+
uv run pytest
|
|
190
|
+
```
|
|
132
191
|
|
|
133
192
|
## 🏃 Other Tools Of Note
|
|
134
193
|
|
|
@@ -136,4 +195,6 @@ _Are you a regex pro?_ Benchmark and submit a pr with improved regex for the [li
|
|
|
136
195
|
- [djangofmt](https://github.com/UnknownPlatypus/djangofmt) A fast, HTML-aware Django/Jinja template formatter written in Rust that formats HTML and template syntax together.
|
|
137
196
|
- [DjHTML](https://github.com/rtts/djhtml) A pure-Python Django/Jinja template indenter without dependencies.
|
|
138
197
|
- [prettier-plugin-jinja-template](https://github.com/davidodenwald/prettier-plugin-jinja-template) Prettier plugin for formatting Jinja and Django templates.
|
|
198
|
+
- [prettier-plugin-twig](https://github.com/zackad/prettier-plugin-twig) Prettier plugin for formatting Twig templates.
|
|
139
199
|
- [Twig-CS-Fixer](https://github.com/VincentLanglet/Twig-CS-Fixer) A PHP tool that lints and automatically fixes Twig coding-standard issues.
|
|
200
|
+
- [ludtwig](https://github.com/MalteJanz/ludtwig) A fast Rust linter and formatter for Twig templates that also validates HTML structure and supports auto-fix.
|
package/package.json
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "djlint",
|
|
3
|
-
"version": "1.42.
|
|
3
|
+
"version": "1.42.3",
|
|
4
4
|
"description": "HTML Template Linter and Formatter",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"html template linter",
|
|
7
7
|
"html template formatter",
|
|
8
|
+
"django template linter",
|
|
9
|
+
"django template formatter",
|
|
8
10
|
"jinja template linter",
|
|
9
11
|
"jinja template formatter",
|
|
10
|
-
"nunjucks template linter",
|
|
11
|
-
"nunjucks template formatter",
|
|
12
12
|
"twig template linter",
|
|
13
13
|
"twig template formatter",
|
|
14
|
+
"nunjucks template linter",
|
|
15
|
+
"nunjucks template formatter",
|
|
14
16
|
"handlebars template linter",
|
|
15
17
|
"handlebars template formatter",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
+
"liquid template linter",
|
|
19
|
+
"liquid template formatter",
|
|
20
|
+
"go template linter",
|
|
21
|
+
"go template formatter",
|
|
18
22
|
"golang template linter",
|
|
19
23
|
"golang template formatter",
|
|
20
24
|
"angular template linter",
|
|
21
|
-
"angular template formatter"
|
|
25
|
+
"angular template formatter",
|
|
26
|
+
"mustache template linter",
|
|
27
|
+
"mustache template formatter",
|
|
28
|
+
"tera template linter",
|
|
29
|
+
"tera template formatter",
|
|
30
|
+
"askama template linter",
|
|
31
|
+
"askama template formatter"
|
|
22
32
|
],
|
|
23
33
|
"homepage": "https://djlint.com",
|
|
24
34
|
"bugs": {
|
|
@@ -35,7 +45,7 @@
|
|
|
35
45
|
},
|
|
36
46
|
"files": [],
|
|
37
47
|
"scripts": {
|
|
38
|
-
"postinstall": "python3 -m pip install --upgrade djlint==1.42.
|
|
48
|
+
"postinstall": "python3 -m pip install --upgrade djlint==1.42.3"
|
|
39
49
|
},
|
|
40
50
|
"devDependencies": {
|
|
41
51
|
"@ianvs/prettier-plugin-sort-imports": "4.7.1",
|