Note
Если команда djlint
не найдена, убедитесь, что Python находится в вашем пути.
djLint собирается с Python 3.7+, он может быть установлен простым запуском:
pip install djlint
Или с помощью npm экспериментальная установка - Обратите внимание, это требует, чтобы python и pip были в вашем системном пути.
npm i djlint
djLint - это приложение командной строки. Для расширенной настройки смотрите конфигурация
.
Usage: djlint [OPTIONS] SRC ...
djLint · lint and reformat HTML templates.
Options:
--version Show the version and exit.
-e, --extension TEXT File extension to check [default: html]
-i, --ignore TEXT Codes to ignore. ex: "H014,H017"
--reformat Reformat the file(s).
--check Check formatting on the file(s).
--indent INTEGER Indent spacing. [default: 4]
--quiet Do not print diff when reformatting.
--profile TEXT Enable defaults by template language. ops: django,
jinja, nunjucks, handlebars, golang, angular,
html [default: html]
--require-pragma Only format or lint files that starts with a comment
with the text 'djlint:on'
--lint Lint for common issues. [default option]
--use-gitignore Use .gitignore file to extend excludes.
--warn Return errors as warnings.
--preserve-leading-space Attempt to preserve leading space on text.
--preserve-blank-lines Attempt to preserve blank lines.
--format-css Also format contents of <style> tags.
--format-js Also format contents of <script> tags.
--configuration PATH Path to global configuration file in .djlintrc format
--statistics Count the number of occurrences of each
error/warning code.
-h, --help Show this message and exit.
djLint работает с путем или stdin.
Бег с тропинкой -
djlint /path/to/templates --lint
Или конкретный файл -
djlint /path/to/this.mustache --lint
Или с помощью stdin -
echo "<div></div>" | djlint -
Stdin также может быть использован для переформатирования кода. На выходе будет только отформатированный код без сообщений.
echo "<div></div>" | djlint - --reformat
Выход -
<div></div>