prettier-plugin-jinja-template
TypeScript icon, indicating that this package has built-in type declarations

1.3.3 • Public • Published

prettier-plugin-jinja-template

Formatter plugin for jinja2 template files.

Install

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

Add the plugin to your .prettierrc:

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

Use

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

{
  "overrides": [
    {
      "files": ["*.html"],
      "options": {
        "parser": "jinja-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-jinja-template

Ignoring Code

Using range ignores is the best way to tell prettier to igone part of files. Most of the time this is necessary for Jinja 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} />
Default CLI Override API Override
true --no-quote-attributes quoteAttributes: <bool>

Dependencies (0)

    Dev Dependencies (6)

    Package Sidebar

    Install

    npm i prettier-plugin-jinja-template

    Weekly Downloads

    4,704

    Version

    1.3.3

    License

    MIT

    Unpacked Size

    47.7 kB

    Total Files

    91

    Last publish

    Collaborators

    • davidodenwald