Djhtml

screenshot of Djhtml

Django/Jinja template indenter

Overview

DjHTML is a pure-Python Django/Jinja template indenter that does not require any dependencies. It is designed to indent mixed HTML/CSS/JavaScript templates that contain Django or Jinja template tags. Unlike other code-formatting tools, DjHTML is an indenter, not a formatter, meaning it will only add or remove whitespace at the beginning of lines. DjHTML is useful for correctly indenting already well-structured templates.

Features

  • Multi-line HTML elements: DjHTML can now indent multi-line HTML elements and multi-line attribute values.
  • Multi-line CSS indentation: Multi-line CSS values are now continued at the same indentation level.
  • Improved JavaScript indentation: DjHTML has added new indentation rules for JavaScript, such as method chaining.
  • Tabwidth guessing: DjHTML no longer defaults to a tabwidth of 4, but instead guesses the correct tabwidth.

Summary

DjHTML is a Python library that provides an indenter for Django/Jinja templates. It can indent mixed HTML/CSS/JavaScript templates that contain Django or Jinja templatetags. DjHTML is an useful tool for correctly indenting well-structured templates and it offers features such as multi-line HTML element indentation, multi-line CSS indentation, improved JavaScript indentation, and tabwidth guessing. It can be easily installed using pip and requires Python 3.8 or higher.