{"id":13593879,"url":"https://github.com/rtts/djhtml","last_synced_at":"2025-04-11T02:27:34.138Z","repository":{"id":38338707,"uuid":"365528895","full_name":"rtts/djhtml","owner":"rtts","description":"Django/Jinja template indenter","archived":false,"fork":false,"pushed_at":"2024-10-17T18:43:05.000Z","size":213,"stargazers_count":596,"open_issues_count":5,"forks_count":33,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-03T23:43:19.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-08T14:02:41.000Z","updated_at":"2025-04-01T14:25:31.000Z","dependencies_parsed_at":"2024-01-11T19:17:13.177Z","dependency_job_id":"c9f6bcac-8ccb-4bcc-8125-baafdd123aea","html_url":"https://github.com/rtts/djhtml","commit_stats":{"total_commits":175,"total_committers":12,"mean_commits":"14.583333333333334","dds":"0.14857142857142858","last_synced_commit":"47f33ed6988a712ddc87e933fcb056e45e557aa0"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtts%2Fdjhtml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtts%2Fdjhtml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtts%2Fdjhtml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtts%2Fdjhtml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtts","download_url":"https://codeload.github.com/rtts/djhtml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328930,"owners_count":21085422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:25.745Z","updated_at":"2025-04-11T02:27:29.129Z","avatar_url":"https://github.com/rtts.png","language":"Python","readme":"# DjHTML\n\n***A pure-Python Django/Jinja template indenter without dependencies.***\n\n```jinja\n{% block content %}\n    \u003cblockquote\n        cite=\"Guido Van Rossum\"\n        class=\"Pythonic\"\n    \u003e\n        {% blocktranslate trimmed %}\n            Don't you hate code that's not properly indented?\n        {% endblocktranslate %}\n    \u003c/blockquote\u003e\n{% endblock %}\n```\n\nDjHTML indents mixed HTML/CSS/JavaScript templates that contain\n[Django](https://docs.djangoproject.com/en/stable/ref/templates/language/)\nor [Jinja](https://jinja.palletsprojects.com/templates/) template\ntags. It works similar to other code-formatting tools such as\n[Black](https://github.com/psf/black) and interoperates nicely with\n[pre-commit](https://pre-commit.com/).\n\nDjHTML is an _indenter_ and not a _formatter_: it will only add/remove\nwhitespace at the beginning of lines. It will not insert newlines or\nother characters. The goal is to correctly indent already\nwell-structured templates, not to fix broken ones.\n\n\n## Installation\n\nDjHTML requires Python 3.9 or higher and is compatible with all\noperating systems supported by Python. Install DjHTML with the\nfollowing command:\n\n    $ pip install djhtml\n\nNote that\n[Windows still uses legacy code pages](https://docs.python.org/3/using/windows.html#win-utf8-mode)\ninstead of UTF-8. It is highly advised to set the environment variable\n`PYTHONUTF8` to `1` with the\n[setx](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/setx)\ncommand:\n\n    C:\\\u003e setx /m PYTHONUTF8 1\n\n\n## Usage\n\nAfter installation you can indent templates using the `djhtml`\ncommand:\n\n    $ djhtml template.html\n    reindented template.html\n    1 template has been reindented.\n\nYou can also run `djhtml .` to indent all HTML files beneath the\ncurrent directory.\n\nAn exit status of 0 means that everything went well, regardless of\nwhether any files were changed. When the option `-c` / `--check` is\nused, the exit status is 1 when one or more files would have changed,\nbut no changes are actually made. All available options are given by\n`djthml -h` / `djthml --help`.\n\n\n## `fmt:off` and `fmt:on`\n\nYou can exclude specific lines from being processed with the\n`{# fmt:off #}` and `{# fmt:on #}` operators:\n\n```jinja\n{# fmt:off #}\n   ,-._|\\\n  /     .\\\n  \\_,--._/\n{# fmt:on #}\n```\n\nContents inside `\u003cpre\u003e ... \u003c/pre\u003e`, `\u003c!-- ... ---\u003e`, `/* ... */`, and\n`{% comment %} ... {% endcomment %}` tags are also ignored (depending\non the current mode).\n\n\n## Modes\n\nThe indenter operates in one of three different modes:\n\n- DjHTML mode: the default mode. Invoked by using the `djhtml` command\n  or the pre-commit hook.\n\n- DjCSS mode. Will be entered when a `\u003cstyle\u003e` tag is encountered in\n  DjHTML mode. It can also be invoked directly with the command\n  `djcss`.\n\n- DjJS mode. Will be entered when a `\u003cscript\u003e` tag is encountered in\n  DjHTML mode. It can also be invoked directly with the command\n  `djjs`.\n\n\n## pre-commit configuration\n\nA great way to use DjHTML is as a [pre-commit](https://pre-commit.com/)\nhook, so all your HTML, CSS and JavaScript files will automatically be\nindented upon every commit.\n\nFirst, install pre-commit:\n\n    $ pip install pre-commit\n    $ pre-commit install\n\nThen, add the following to your `.pre-commit-config.yaml`:\n\n```yml\nrepos:\n  - repo: https://github.com/rtts/djhtml\n    rev: 'main'  # replace with the latest tag on GitHub\n    hooks:\n      - id: djhtml\n      - id: djcss\n      - id: djjs\n```\n\nNow run `pre-commit autoupdate` to automatically replace `main` with\nthe latest tag on GitHub,\n[as recommended by pre-commit](https://pre-commit.com/#using-the-latest-version-for-a-repository).\n\nIf you want to override a command-line option, for example to change\nthe default tabwidth, you change the `entry` point of these hooks:\n\n```yml\n    hooks:\n      - id: djhtml\n        # Use a tabwidth of 2 for HTML files\n        entry: djhtml --tabwidth 2\n      - id: djcss\n      - id: djjs\n```\n\nIf you want to limit the files these hooks operate on, you can use\n[pre-commit mechanisms for filtering](https://pre-commit.com/#filtering-files-with-types).\nFor example:\n\n```yml\n    hooks:\n      - id: djhtml\n        # Indent only HTML files in template directories\n        files: .*/templates/.*\\.html$\n      - id: djcss\n        # Run this hook only on SCSS files (CSS and SCSS is the default)\n        types: [scss]\n      - id: djjs\n        # Exclude JavaScript files in vendor directories\n        exclude: .*/vendor/.*\n```\n\nNow when you run `git commit` you will see something like the\nfollowing output:\n\n    $ git commit\n\n    DjHTML...................................................................Failed\n    - hook id: djhtml\n    - files were modified by this hook\n\n    reindented template.html\n    1 template has been reindented.\n\nTo inspect the changes that were made, use `git diff`. If you are\nhappy with the changes, you can commit them normally. If you are not\nhappy, please do the following:\n\n1. Run `SKIP=djhtml git commit` to commit anyway, skipping the\n   `djhtml` hook.\n\n2. Consider [opening an issue](https://github.com/rtts/djhtml/issues)\n   with the relevant part of the input file that was incorrectly\n   formatted, and an example of how it should have been formatted.\n\nYour feedback for improving DjHTML is very welcome!\n\n\n## Development\n\nFirst of all, clone this repository:\n\n    $ git clone https://github.com/rtts/djhtml\n    $ cd djhtml\n\nThen, create a Python virtualenv and activate it:\n\n    $ python -m venv ~/.virtualenvs/djhtml\n    $ . ~/.virtualenvs/djhtml/bin/activate\n\nThen, install the package in [development\nmode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html)\nincluding the `dev` dependencies, and install the pre-commit hooks:\n\n    $ python -m pip install -e '.[dev]'\n    $ pre-commit install --install-hooks\n\nYou can run the unittests with:\n\n    $ python -m unittest\n\nOr use [`nox`](https://nox.thea.codes) to test all supported Python\ninterpreters:\n\n    $ nox\n\nFinally, to get a little insight into the tokenization step of the\nindenting algorithm, you can run DjHTML with the `-d` / `--debug`\nargument. You will see a Python representation of the tokens that are\ncreated.\n","funding_links":[],"categories":["Python","Developer Tools"],"sub_categories":["Templates"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtts%2Fdjhtml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtts%2Fdjhtml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtts%2Fdjhtml/lists"}