I found that you can use comments to have prettier ignore your tags
My observations:
djhtmlonly indents,djlintis too slow (see [BUG] djlint --check/--reformat takes 21 seconds on long file. Increase speed? Ā· Issue #104 Ā· Riverside-Healthcare/djLint Ā· GitHub),prettiermangles Django tags.
I was so desperate that I wanted to write a prettier plugin, but luckily I have found a working one (with exactly zero stars) - GitHub - sezze/prettier-plugin-django-alpine: Format Django tags and Alpine.js in HTML files.
For VSCode it requires extension & local installation of prettier - you may need to use "prettier.prettierPath": "./node_modules/prettier/index.cjs" in your settings.json (as newbie I am not allowed to add the 3rd link to this post).
I use TailwindCSS and need sorting of class names - it would be nice if it is done by prettier to. But the official plugin prettier-plugin-tailwindcss is crazy and whitelists (actually embeds) compatible (presumably popular) plugins. So I made a fork and now I can have support for it all: GitHub - brablc/prettier-plugin-tailwindcss-django-alpine: A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order. .
Thanks! FWIW, the performance issue with djlint was apparently fixed a couple of months ago.
I note your fork, prettier-plugin-tailwindcss-django-alpine, hasnāt had an update in about two years. Are you still using it, or would you recommend something else now?
Hi, I am using it all the time (eventhough I have switched from VSCode to Lazyvim) and I have upgraded it to Tailwind CSS on request from @eyalch just now.
I was for long trying to use dprint + markup_fmt (markup_fmt Plugin - dprint - Code Formatter)
and ended up finding this neat project:
GitHub - UnknownPlatypus/djangofmt: A fast, HTML aware, Django template formatter, written in Rust.
Anyone tried this out? I will certainly do.
Same, that why I built djangofmt to add django support to markup_fmt and make it easier to use for django projects that might not use dprint.
I test on a bunch of open source django project in CI, feel free to add more to help make the tool better !
People might also be interested in GitHub - adamchainz/djade: A Django template formatter. Ā· GitHub which does some syntax upgrading, similar to django-upgrade. It complements well djangofmt
Is it possible to set djangofmt up as a formatter in something like Helix or Zed? To do that, I think it would need to read from stdin and write to stdout. I couldnāt find anything in the documentation talking about that functionality.
@trey This was indeed not supported (not a zed/helix user, didnāt know it needed that) but I just released a new version adding support for it. Iāve added sample configs for zed/helix inspired from their documentation. Feel free to try it out and open issues if you have problems
Fantastic, thank you! I donāt suppose thereās much desire for the option to use tabs instead of spaces, huh?
Would be a oneliner to add, feel free to open an issue if itās useful to you.
I tried to use sane defaults and minimal configuration to keep things simple but am open to add some if it helps and is not too much work