beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.52k stars 1.36k forks source link

CSS formatter does not support `django` templating #1979

Open mjnaderi opened 2 years ago

mjnaderi commented 2 years ago

Description

When formatting a CSS file with django template tags or an HTML file which contains django template inside <style> tag, styles are not formatted correctly.

Input

The code looked like this before beautification:

<style>
  {% if condition %}
    .important {color: red}
  {% else %}
    .important {color: blue}
  {% endif %}
</style>

Expected Output

The code should have looked like this after beautification:

<style>
  {% if condition %}
    .important {
      color: red
    }
  {% else %}
    .important {
      color: blue
    }
  {% endif %}
</style>

Actual Output

The code actually looked like this after beautification:

<style>
  {
    % if condition %
  }

  .important {
    color: red
  }

    {
    % else %
  }

  .important {
    color: blue
  }

    {
    % endif %
  }
</style>

Steps to Reproduce

npm install js-beautify
./node_modules/js-beautify/js/bin/js-beautify.js --type html --templating django file.html
# - OR -
./node_modules/js-beautify/js/bin/js-beautify.js --type css --templating django file.css

Environment

OS: Linux

bitwiseman commented 2 years ago

Yup. The CSS beautifier is the crustiest part of this product. Contributors needed.