Django模板上的vscode html自动格式化 [英] vscode html autoformat on django template

查看:1088
本文介绍了Django模板上的vscode html自动格式化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢保存自动格式化的VSCode,直到它与我的模板代码搞混为止。

I love VSCode on save autoformat until it messed up with my template code.

错误地将Django模板语法格式化为一行代码(有时很长的行) 。因此,不要使用此代码

It wrongly formats my django template syntax into one line code (sometimes really long line). So instead of having this code

{% for row in 'ABCDEFGH' %}
<tr>
  {% for col in '123456789012345' %}
    <td>
      {% with forloop.counter|stringformat:"s" as counter %}
        {% with row|add:counter as seat_num %}
          {% if seat_num not in oc_seats %}
            <input type="checkbox" value="{{ row }}{{ forloop.counter }}" name="seats">
          {% endif %}
          <br> {{ seat_num }} 
        {% endwith %}
      {% endwith %}
     </td>    
   {% endfor %}
</tr>
{% endfor %}

我最终拥有此代码

{% for row in 'ABCDEFGH' %}
<tr>
  {% for col in '123456789012345' %}
  <td style="text-align: center; border: 1px solid #aaa;">
    {% with forloop.counter|stringformat:"s" as counter %} {% with row|add:counter as seat_num %} {% if seat_num not in oc_seats %}
    <input type="checkbox" value="{{ row }}{{ forloop.counter }}" name="seats"> {% endif %} {{ seat_num }} {% endwith %} {% endwith %}
  </td>
  {% endfor %}
</tr>
{% endfor %}

我试图通过将用户设置更改为保存来禁用格式 { editor.formatOnSave:false} 但还是没有运气。

I tried to disable format on save by changing user settings into {"editor.formatOnSave": false} but still haven't gotten any luck.

是否有任何配置

PS:
我在Sierra MacOSx上使用VSCode 1.9版

PS: I'm using VSCode version 1.9 on Sierra MacOSx

推荐答案

您可以禁用默认的html格式程序,转到文件>首选项>用户或工作区设置,在HTML设置中,您将找到:

you can disable the default html formatter, goto File > Preferences > User or Workspace Settings, in HTML settings you will find :

// Enable/disable default HTML formatter (requires restart)
  "html.format.enable": true,

我认为VSCode使用js-beautify作为默认格式化程序,您可以使用美化扩展名,以在项目目录中使用.jsbeautifyrc覆盖其设置

I think VSCode uses js-beautify as default formatter, you can use beautify extension to override it settings with .jsbeautifyrc in project directory

这篇关于Django模板上的vscode html自动格式化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆