The Missing Formatter and Linter for HTML Templates

May 12, 2024 | Programming

djLint Logo

Maintainers needed, please reach out on discord or email!


tweet


Discord Chat


Codecov Status


Codacy Status


Downloads


npm


Pypi Download

How to useКак пользоватьсяUtilisation

What language are you using?

Django
Jinja
Nunjucks
Twig
Handlebars
Mustache
GoLang
Angular

For What?

Once upon a time, all the other programming languages had a formatter and linter: CSS, JavaScript, Python, the C suite, TypeScript, Ruby, PHP, Go, Swift, and many others. Yet, HTML templates found themselves in the cold, unformatted and unlinted. They were the neglected corner in your repository. Something had to change. djLint is a community-built project aimed to add consistency to HTML templates.

How to Use djLint

Getting started with djLint is as simple as making a cup of coffee. You just need to install it and start formatting your HTML templates.

  • Install it using pip:
    pip install djlint
  • Or, if preferred, use npm (requires Python and pip to be on your system path):
    npm i djlint
  • To lint your project:
    djlint . --extension=html.j2 --lint
  • To check your format:
    djlint . --extension=html.j2 --check
  • To fix the format:
    djlint . --extension=html.j2 --reformat

Like it? Add a Badge!

Add a badge to your project’s README.md:

[![Code style: djlint](https://img.shields.io/badge/html%20style-djlint-blue.svg)](https://www.djlint.com)

Add a badge to your README.rst:

.. image:: https://img.shields.io/badge/html%20style-djlint-blue.svg
:target: https://www.djlint.com

Looks like this:

[![djLint](https://img.shields.io/badge/html%20style-djLint-blue.svg)](https://github.com/djlint/djlint)

Can I Help?

Yes! Would you like to add a rule to the linter? Take a look at the linter docs and source code. Are you a regex pro? Benchmark and submit a PR with improved regex for the linter rules. Help Needed! Good with Python? djLint was an experimental project that is catching on with other developers. Help out with a rewrite of the formatter to improve speed and HTML style for edge cases. Contribute on the 2.0 branch.

Other Tools of Note

  • DjHTML – A pure-Python Django/Jinja template indenter without dependencies.
  • HTMLHint – Static code analysis tool you need for your HTML.
  • curlylint – Experimental HTML templates linting for Jinja, Nunjucks, Django templates, Twig, Liquid.

Troubleshooting

You may encounter issues such as installation errors or linting problems. Here are some troubleshooting tips:

  • Ensure that Python and pip are correctly installed and added to your system’s PATH.
  • If you have issues related to npm, check your Node.js installation.
  • Revisit the installation commands for accuracy, especially ensuring there are no typos.
  • Consult the documentation for any specific error messages you come across.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox