djLint/docs/djlint/usage.rst

121 lines
2.5 KiB
ReStructuredText
Raw Normal View History

2021-07-29 18:41:34 +00:00
Getting Started
================
Installation from `Pypi <https://pypi.org/project/djlint/>`__
--------------------------------------------------------------
.. code:: sh
pip install djlint
Linter Usage
------------
.. code:: sh
djlint src # file or path
# with custom extensions
djlint src -e html.dj
Formatter Usage
---------------
2021-07-29 18:41:34 +00:00
Foramtting is a beta tool. ``--check`` the output before applying changes.
2021-07-29 18:41:34 +00:00
Reformatting does not work with long json/html embedded into attribute data.
2021-10-05 06:36:57 +00:00
To review what may change in formatting run:
2021-07-29 18:41:34 +00:00
.. code:: sh
djlint . --check --ignore="H014,H017"
2021-07-29 18:41:34 +00:00
2021-10-05 06:36:57 +00:00
To format the code and update files run:
2021-07-29 18:41:34 +00:00
.. code:: sh
2021-09-30 08:02:05 +00:00
djlint . --reformat --indent=3
2021-07-29 18:41:34 +00:00
Ignoring Code
-------------
Code can be skipped by the linter and formatter by wrapping in djlint tags:
.. code:: html
2021-10-14 10:19:48 +00:00
<!-- djlint:off -->
<bad html to ignore>
<!-- djlint:on -->
or
{# djlint:off #}
<bad html to ignore>
{# djlint:on #}
or
{% comment %} djlint:off {% endcomment %}
<bad html to ignore>
{% comment %} djlint:on {% endcomment %}
or
{{ /* djlint:off */ }}
<bad html to ignore>
{{ /* djlint:on */ }}
or
{{!-- djlint:off --}}
<bad html to ignore>
{{!-- djlint:on --}}
2021-09-16 11:36:44 +00:00
Stdin vs Path
-------------
djLint also works with stdin.
.. code:: sh
echo "<div></div>" | djlint -
2021-10-05 11:11:08 +00:00
Stdin can also be used to reformat code. The output will be only the formatted code without messages.
.. code:: sh
echo "<div></div>" | djlint - --reformat
Output -
.. code:: html
<div></div>
2021-07-29 18:41:34 +00:00
CLI Args
--------
2021-07-29 18:41:34 +00:00
.. code:: sh
2021-10-05 06:34:35 +00:00
Usage: python -m djlint [OPTIONS] SRC ...
2021-07-29 18:41:34 +00:00
2021-10-14 10:19:48 +00:00
djLint · lint and reformat HTML templates.
2021-07-29 18:41:34 +00:00
Options:
2021-10-05 06:34:35 +00:00
--version Show the version and exit.
2021-10-14 10:19:48 +00:00
-e, --extension TEXT File extension to check [default: html]
2021-10-05 06:34:35 +00:00
-i, --ignore TEXT Codes to ignore. ex: "H014,H017"
2021-07-29 18:41:34 +00:00
--reformat Reformat the file(s).
--check Check formatting on the file(s).
2021-10-14 10:19:48 +00:00
--indent INTEGER Indent spacing. [default: 4]
2021-07-29 18:41:34 +00:00
--quiet Do not print diff when reformatting.
2021-10-05 06:34:35 +00:00
--profile TEXT Enable defaults by template language. ops: django,
jinja, nunjucks, handlebars, golang
2021-10-14 10:19:48 +00:00
--require-pragma Only format or lint files that starts with a comment
with the text 'djlint:on'
--lint Lint for common issues. [default option]
2021-07-29 18:41:34 +00:00
-h, --help Show this message and exit.