djlint / djlint-vscode

VS Code extension for formatting and linting HTML templates (Django, Jinja, Nunjucks, Twig, Handlebars, Mustache).
https://marketplace.visualstudio.com/items?itemName=monosans.djlint
MIT License
54 stars 2 forks source link
studio visual

djlint-vscode

CI Visual Studio Marketplace Installs Open VSX Downloads

Visual Studio Code extension for formatting and linting HTML templates (Django, Jinja, Nunjucks, Twig, Handlebars, Mustache) using djLint.

Installation

  1. Install djLint itself with the python -m pip install -U djlint command.
  2. Install djLint VS Code extension from Visual Studio Marketplace or Open VSX.

Usage

If you have the Python extension installed, djlint-vscode will use the djLint installed in the currently activated Python environment, unless you have the djlint.useVenv extension setting disabled.

The extension can be configured through the settings in VS Code. Some options can be configured through the djLint configuration file.

Add this to your settings.json to format the default enabled languages with djLint:

"[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
  "editor.defaultFormatter": "monosans.djlint"
}

Usage with djLint installed with pipx

pipx creates a separate venv for each application. You can see where it creates the venv with the pipx environment --value PIPX_LOCAL_VENVS command. For me it is /home/user/.local/share/pipx/venvs. This way I can set these settings:

"djlint.useVenv": false,
"djlint.pythonPath": "/home/user/.local/share/pipx/venvs/djlint/bin/python",

Usage with djLint installed with uv

uv creates a separate venv for each application. You can see where it creates the venv with the uv tool dir command. For me it is /home/user/.local/share/share/uv/tools. This way I can set these settings:

"djlint.useVenv": false,
"djlint.pythonPath": "/home/user/.local/share/share/uv/tools/djlint/bin/python",

Known issues

License

MIT