0.1.1 • Published 4 months ago

prettier-plugin-django-template v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

prettier-plugin-django-template

Formatter plugin for Django template files.

Install

npm install --save-dev prettier prettier-plugin-django-template

Add the plugin to your .prettierrc:

{
  "plugins": ["prettier-plugin-django-template"]
}

Use

To format basic .html files, you'll have to override the used parser inside your .prettierrc:

{
  "overrides": [
    {
      "files": ["*.html"],
      "options": {
        "parser": "django-template"
      }
    }
  ]
}

Run it on all html files in your project:

npx prettier --write **/*.html

If you don't have a prettier config you can run the plugin with this command:

npx prettier --write **/*.html --plugin=prettier-plugin-django-template

Ignoring Code

Using range ignores is the best way to tell prettier to ignore part of files. Most of the time this is necessary for Django tags inside script or style tags:

<!-- prettier-ignore-start -->
  <script>
    window.someData = {{ data | safe }}
  </script>
<!-- prettier-ignore-end -->

<!-- prettier-ignore-start -->
  <style>
    :root { --accent-color: {{ theme_accent_color }} }
  </style>
<!-- prettier-ignore-end -->

Options

This Plugin provides additional options:

Quote Attributes

Surrounds the value of html attributes with quotes. This option was introduced to support JinjaX syntax.

true - Example:

<Paginator items="{products}" />

false - Example:

<Paginator items={products} />
DefaultCLI OverrideAPI Override
true--no-quote-attributesquoteAttributes: <bool>
0.1.1

4 months ago

0.1.0

4 months ago