# DjHTML ***A pure-Python Django/Jinja template indenter without dependencies.*** ```jinja {% block content %}
{% blocktranslate trimmed %} Don't you hate code that's not properly indented? {% endblocktranslate %}{% endblock %} ``` DjHTML indents mixed HTML/CSS/JavaScript templates that contain [Django](https://docs.djangoproject.com/en/stable/ref/templates/language/) or [Jinja](https://jinja.palletsprojects.com/templates/) template tags. It works similar to other code-formatting tools such as [Black](https://github.com/psf/black) and interoperates nicely with [pre-commit](https://pre-commit.com/). DjHTML is an _indenter_ and not a _formatter_: it will only add/remove whitespace at the beginning of lines. It will not insert newlines or other characters. The goal is to correctly indent already well-structured templates, not to fix broken ones. If you are looking for an actual template _formatter_, check out the [djangofmt](https://github.com/UnknownPlatypus/djangofmt) project. ## Installation DjHTML requires Python 3.9 or higher and is compatible with all operating systems supported by Python. Install DjHTML with the following command: $ pip install djhtml Note that [Windows still uses legacy code pages](https://docs.python.org/3/using/windows.html#win-utf8-mode) instead of UTF-8. It is highly advised to set the environment variable `PYTHONUTF8` to `1` with the [setx](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/setx) command: C:\> setx /m PYTHONUTF8 1 ## Usage After installation you can indent templates using the `djhtml` command: $ djhtml template.html reindented template.html 1 template has been reindented. You can also run `djhtml .` to indent all HTML files beneath the current directory. An exit status of 0 means that everything went well, regardless of whether any files were changed. When the option `-c` / `--check` is used, the exit status is 1 when one or more files would have changed, but no changes are actually made. All available options are given by `djthml -h` / `djthml --help`. ### Command-line arguments DjHTML supports the following command-line arguments: - `-h` / `--help`: Show help text. - `-v` / `--version`: Show version number. - `-c` / `--check`: Dry-run, checks without modifying files. - `-t` / `--tabwidth N`: Tabwidth. The default is to guess. - `-b` / `--extra-block BEGIN,END`: Define an extra non-standard block tag. Can be used multiple times. ## `fmt:off` and `fmt:on` You can exclude specific lines from being processed with the `{# fmt:off #}` and `{# fmt:on #}` operators: ```jinja {# fmt:off #} ,-._|\ / .\ \_,--._/ {# fmt:on #} ``` Contents inside `
...`, ``, `/* ... */`, and `{% comment %} ... {% endcomment %}` tags are also ignored (depending on the current mode). ## Modes The indenter operates in one of three different modes: - DjHTML mode: the default mode. Invoked by using the `djhtml` command or the pre-commit hook. - DjCSS mode. Will be entered when a `