Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter removes all indentations #134

Open
tk-90-github opened this issue Apr 21, 2023 · 3 comments
Open

Formatter removes all indentations #134

tk-90-github opened this issue Apr 21, 2023 · 3 comments

Comments

@tk-90-github
Copy link

I like the syntax highlighting and formatting much EXCEPT:

When i indent my blocks and conditional statements, all the identation is removed.

Disabling this plugin solved it but that's not what I like to do.

Can you provide me a solution/some settings.json-config for VSCode or get a fix for it?

@RyanBaig
Copy link

RyanBaig commented Jan 1, 2024

its probably because html formatter and such dont know what to do with jinja template tags, and just write them like plaintext. Please also let me know if u find a formatter that works with this extension,

@samuelcolvin
Copy link
Owner

There's no solution I know of for this.

@Rawk
Copy link

Rawk commented Oct 16, 2024

I finally found a solution that seems to work for me.

Use the VS Code extension Prettier for nice HTML formatting, with the Prettier plugin prettier-plugin-jinja-template to make Prettier aware of Jinja syntax.

There is multiple ways to set it up. Since i already used npm, i added it with:

npm install --dev --save-exact prettier prettier-plugin-jinja-template

This forces the Prettier extension to use the Prettier version inside node_modules/prettier.

Add Prettier config to package.json making it look something like this:

{
  "devDependencies": {
    "prettier": "3.3.3",
    "prettier-plugin-jinja-template": "2.0.0"
  },
  "prettier": {
    "plugins": ["prettier-plugin-jinja-template"]
  }
}

Set Prettier as default formatter for jinja-html in VS Code settings:

{
  "[jinja-html]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants