Add a formatter (beautifier) to django-html files in Visual Studio Code

混江龙づ霸主 提交于 2021-01-28 09:40:31

问题


I'm using the Django extension for intellisense and syntax highlighting on Jinja templates (VS Code) but cannot figure out how to use my default formatter (HookyQR Beautify) to beautify/format my django-html files. Would that be possible?


回答1:


I need to use beautify only for django-html files, I've got prettier working for js, html, css then flake8 and autopep8 for python, for django-html prettier wrongly formats jinja template strings,

so I disabled the django-html from pettier languages and used these settings got from this issue discussion., works for me well.

{
    "prettier.disableLanguages": ["django-html"],
    "beautify.language": {
      "html": [
        "django-html"
      ]
    },
    "[django-html]": {
      "editor.formatOnSave": true,
      "editor.defaultFormatter": "HookyQR.beautify"
    }
  }



回答2:


This seems to have sorted it for me, allowing me to keep HookyQR Beautify for normal HTML files and have a separate one for django-html files:

"beautify.language": {
    "html": [
        "django-html"
    ]
}


来源:https://stackoverflow.com/questions/61224427/add-a-formatter-beautifier-to-django-html-files-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!